]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip-route: Fix for memleak in error path
authorPhil Sutter <phil@nwl.cc>
Thu, 18 Oct 2018 12:30:31 +0000 (14:30 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 22 Oct 2018 17:05:43 +0000 (10:05 -0700)
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>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/iproute_lwtunnel.c

index 969a4763df71d1dc118919b9ce702c9adf0d0f78..85045d4fff74207d3db5e2d5c4699fbda622a5b0 100644 (file)
@@ -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 {