netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [iproute PATCH] ip-route: Fix for memleak in error path
@ 2018-10-18 12:30 Phil Sutter
  2018-10-22 17:06 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Sutter @ 2018-10-18 12:30 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

If call to rta_addattr_l() failed, parse_encap_seg6() would leak memory.
Fix this by making sure calls to free() are not skipped.

Fixes: bd59e5b1517b0 ("ip-route: Fix segfault with many nexthops")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 ip/iproute_lwtunnel.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index 969a4763df71d..85045d4fff742 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -498,6 +498,7 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
 	int argc = *argcp;
 	int encap = -1;
 	__u32 hmac = 0;
+	int ret = 0;
 	int srhlen;
 
 	while (argc > 0) {
@@ -539,16 +540,19 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,
 	memcpy(tuninfo->srh, srh, srhlen);
 
 	if (rta_addattr_l(rta, len, SEG6_IPTUNNEL_SRH, tuninfo,
-			  sizeof(*tuninfo) + srhlen))
-		return -1;
-
-	free(tuninfo);
-	free(srh);
+			  sizeof(*tuninfo) + srhlen)) {
+		ret = -1;
+		goto out;
+	}
 
 	*argcp = argc + 1;
 	*argvp = argv - 1;
 
-	return 0;
+out:
+	free(tuninfo);
+	free(srh);
+
+	return ret;
 }
 
 struct lwt_x {
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [iproute PATCH] ip-route: Fix for memleak in error path
  2018-10-18 12:30 [iproute PATCH] ip-route: Fix for memleak in error path Phil Sutter
@ 2018-10-22 17:06 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2018-10-22 17:06 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netdev

On Thu, 18 Oct 2018 14:30:31 +0200
Phil Sutter <phil@nwl.cc> wrote:

> If call to rta_addattr_l() failed, parse_encap_seg6() would leak memory.
> Fix this by making sure calls to free() are not skipped.
> 
> Fixes: bd59e5b1517b0 ("ip-route: Fix segfault with many nexthops")
> Signed-off-by: Phil Sutter <phil@nwl.cc>

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-23  1:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-18 12:30 [iproute PATCH] ip-route: Fix for memleak in error path Phil Sutter
2018-10-22 17:06 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).