naccyde / rpms / iproute

Forked from rpms/iproute 8 months ago
Clone

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

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