Blame SOURCES/0332-sd-netlink-fix-deep-recursion-in-message-destruction.patch

17b0f1
From 164a98ea6b24fea3433516dcc0df496929674cdd Mon Sep 17 00:00:00 2001
17b0f1
From: Jan Synacek <jsynacek@redhat.com>
17b0f1
Date: Tue, 7 Jun 2016 12:43:38 +0200
17b0f1
Subject: [PATCH] sd-netlink: fix deep recursion in message destruction
17b0f1
17b0f1
On larger systems we might very well see messages with thousands of parts.
17b0f1
When we free them, we must avoid recursing into each part, otherwise we
17b0f1
very likely get stack overflows.
17b0f1
17b0f1
Fix sd_netlink_message_unref() to use an iterative approach rather than
17b0f1
recursion (also avoid tail-recursion in case it is not optimized by the
17b0f1
compiler).
17b0f1
17b0f1
(cherry picked from commit 82e4eda664d40ef60829e27d84b1610c2f4070cd)
17b0f1
Resolves: #1330593
17b0f1
---
17b0f1
 src/libsystemd/sd-rtnl/rtnl-message.c | 10 ++++++----
17b0f1
 1 file changed, 6 insertions(+), 4 deletions(-)
17b0f1
17b0f1
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
17b0f1
index 276591f31b..9276bbdebc 100644
17b0f1
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
17b0f1
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
17b0f1
@@ -584,7 +584,9 @@ sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m) {
17b0f1
 }
17b0f1
 
17b0f1
 sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m) {
17b0f1
-        if (m && REFCNT_DEC(m->n_ref) == 0) {
17b0f1
+        sd_rtnl_message *t;
17b0f1
+
17b0f1
+        while (m && REFCNT_DEC(m->n_ref) == 0) {
17b0f1
                 unsigned i;
17b0f1
 
17b0f1
                 free(m->hdr);
17b0f1
@@ -592,9 +594,9 @@ sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m) {
17b0f1
                 for (i = 0; i <= m->n_containers; i++)
17b0f1
                         free(m->rta_offset_tb[i]);
17b0f1
 
17b0f1
-                sd_rtnl_message_unref(m->next);
17b0f1
-
17b0f1
-                free(m);
17b0f1
+                t = m;
17b0f1
+                m = m->next;
17b0f1
+                free(t);
17b0f1
         }
17b0f1
 
17b0f1
         return NULL;