naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

Blame SOURCES/0079-ipvrf-Fix-error-path-of-vrf_switch.patch

36cfb7
From 7ea6dbec34ae5166dd93fd4dbfcab35512e86e94 Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Mon, 29 Apr 2019 20:07:22 +0200
36cfb7
Subject: [PATCH] ipvrf: Fix error path of vrf_switch()
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
36cfb7
Upstream Status: iproute2.git commit 6ac5943bdd5ac
36cfb7
36cfb7
commit 6ac5943bdd5ac5bb8c22b99f5a1d5907ebbcae2b
36cfb7
Author: Phil Sutter <phil@nwl.cc>
36cfb7
Date:   Thu Aug 17 19:09:27 2017 +0200
36cfb7
36cfb7
    ipvrf: Fix error path of vrf_switch()
36cfb7
36cfb7
    Apart from trying to close(-1), this also leaked memory.
36cfb7
36cfb7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
36cfb7
---
36cfb7
 ip/ipvrf.c | 9 +++++----
36cfb7
 1 file changed, 5 insertions(+), 4 deletions(-)
36cfb7
36cfb7
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
36cfb7
index 0f611b44b78ab..ae3b48fa81996 100644
36cfb7
--- a/ip/ipvrf.c
36cfb7
+++ b/ip/ipvrf.c
36cfb7
@@ -369,12 +369,12 @@ static int vrf_switch(const char *name)
36cfb7
 
36cfb7
 	/* -1 on length to add '/' to the end */
36cfb7
 	if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
36cfb7
-		return -1;
36cfb7
+		goto out;
36cfb7
 
36cfb7
 	if (vrf_path(vpath, sizeof(vpath)) < 0) {
36cfb7
 		fprintf(stderr, "Failed to get base cgroup path: %s\n",
36cfb7
 			strerror(errno));
36cfb7
-		return -1;
36cfb7
+		goto out;
36cfb7
 	}
36cfb7
 
36cfb7
 	/* if path already ends in netns then don't add it again */
36cfb7
@@ -425,13 +425,14 @@ static int vrf_switch(const char *name)
36cfb7
 	snprintf(pid, sizeof(pid), "%d", getpid());
36cfb7
 	if (write(fd, pid, strlen(pid)) < 0) {
36cfb7
 		fprintf(stderr, "Failed to join cgroup\n");
36cfb7
-		goto out;
36cfb7
+		goto out2;
36cfb7
 	}
36cfb7
 
36cfb7
 	rc = 0;
36cfb7
+out2:
36cfb7
+	close(fd);
36cfb7
 out:
36cfb7
 	free(mnt);
36cfb7
-	close(fd);
36cfb7
 
36cfb7
 	return rc;
36cfb7
 }
36cfb7
-- 
e138d9
2.21.0
36cfb7