[quagga-dev 12873] [PATCH 4/7] Fixed rtadv_make_socket socket leak

Denil Vira denil at cumulusnetworks.com
Thu Jul 23 14:52:19 BST 2015


Coverity Scan #709790
In zebra/rtadv.c: rtadv_make_socket leaks socket for error cases.
Added lines to close the socket for each error case or return.

Signed-off-by: Morgan Stewart <morgan at cumulusnetworks.com>
---
 rtadv.patch | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 rtadv.patch

diff --git a/rtadv.patch b/rtadv.patch
new file mode 100644
index 0000000..0fdb6fb
--- /dev/null
+++ b/rtadv.patch
@@ -0,0 +1,60 @@
+diff --git a/zebra/rtadv.c b/zebra/rtadv.c
+index b395982..f1188fc 100644
+--- a/zebra/rtadv.c
++++ b/zebra/rtadv.c
+@@ -548,23 +548,41 @@ rtadv_make_socket (void)
+   /* When we can't make ICMPV6 socket simply back.  Router
+      advertisement feature will not be supported. */
+   if (sock < 0)
+-    return -1;
++    {
++      close (sock);
++      return -1;
++    }
+ 
+   ret = setsockopt_ipv6_pktinfo (sock, 1);
+   if (ret < 0)
+-    return ret;
++    {
++      close (sock);
++      return ret;
++    }
+   ret = setsockopt_ipv6_multicast_loop (sock, 0);
+   if (ret < 0)
+-    return ret;
++    {
++      close (sock);
++      return ret;
++    }
+   ret = setsockopt_ipv6_unicast_hops (sock, 255);
+   if (ret < 0)
+-    return ret;
++    {
++      close (sock);
++      return ret;
++    }
+   ret = setsockopt_ipv6_multicast_hops (sock, 255);
+   if (ret < 0)
+-    return ret;
++    {
++      close (sock);
++      return ret;
++    }
+   ret = setsockopt_ipv6_hoplimit (sock, 1);
+   if (ret < 0)
+-    return ret;
++    {
++      close (sock);
++      return ret;
++    }
+ 
+   ICMP6_FILTER_SETBLOCKALL(&filter);
+   ICMP6_FILTER_SETPASS (ND_ROUTER_SOLICIT, &filter);
+@@ -575,6 +593,7 @@ rtadv_make_socket (void)
+   if (ret < 0)
+     {
+       zlog_info ("ICMP6_FILTER set fail: %s", safe_strerror (errno));
++      close (sock);
+       return ret;
+     }
+ 
-- 
1.9.1





More information about the Quagga-dev mailing list