naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0031-ip-route-Fix-for-memleak-in-error-path.patch

930fb9
From 0c762f107e6a5f6c56c42c0aba48f6aa9c6f1eef Mon Sep 17 00:00:00 2001
930fb9
From: Phil Sutter <psutter@redhat.com>
930fb9
Date: Thu, 25 Oct 2018 12:24:30 +0200
930fb9
Subject: [PATCH] ip-route: Fix for memleak in error path
930fb9
930fb9
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1602555
930fb9
Upstream Status: iproute2.git commit e5da392ff8e39
930fb9
930fb9
commit e5da392ff8e3979b86cad04b238ffbbc8076e005
930fb9
Author: Phil Sutter <phil@nwl.cc>
930fb9
Date:   Thu Oct 18 14:30:31 2018 +0200
930fb9
930fb9
    ip-route: Fix for memleak in error path
930fb9
930fb9
    If call to rta_addattr_l() failed, parse_encap_seg6() would leak memory.
930fb9
    Fix this by making sure calls to free() are not skipped.
930fb9
930fb9
    Fixes: bd59e5b1517b0 ("ip-route: Fix segfault with many nexthops")
930fb9
    Signed-off-by: Phil Sutter <phil@nwl.cc>
930fb9
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
930fb9
---
930fb9
 ip/iproute_lwtunnel.c | 16 ++++++++++------
930fb9
 1 file changed, 10 insertions(+), 6 deletions(-)
930fb9
930fb9
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
930fb9
index 969a476..85045d4 100644
930fb9
--- a/ip/iproute_lwtunnel.c
930fb9
+++ b/ip/iproute_lwtunnel.c
930fb9
@@ -498,6 +498,7 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
930fb9
 	int argc = *argcp;
930fb9
 	int encap = -1;
930fb9
 	__u32 hmac = 0;
930fb9
+	int ret = 0;
930fb9
 	int srhlen;
930fb9
 
930fb9
 	while (argc > 0) {
930fb9
@@ -539,16 +540,19 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
930fb9
 	memcpy(tuninfo->srh, srh, srhlen);
930fb9
 
930fb9
 	if (rta_addattr_l(rta, len, SEG6_IPTUNNEL_SRH, tuninfo,
930fb9
-			  sizeof(*tuninfo) + srhlen))
930fb9
-		return -1;
930fb9
-
930fb9
-	free(tuninfo);
930fb9
-	free(srh);
930fb9
+			  sizeof(*tuninfo) + srhlen)) {
930fb9
+		ret = -1;
930fb9
+		goto out;
930fb9
+	}
930fb9
 
930fb9
 	*argcp = argc + 1;
930fb9
 	*argvp = argv - 1;
930fb9
 
930fb9
-	return 0;
930fb9
+out:
930fb9
+	free(tuninfo);
930fb9
+	free(srh);
930fb9
+
930fb9
+	return ret;
930fb9
 }
930fb9
 
930fb9
 struct lwt_x {
930fb9
-- 
930fb9
1.8.3.1
930fb9