]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix memory leaks in ICMP
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 28 Jan 2013 09:59:18 +0000 (02:59 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 28 Jan 2013 09:59:18 +0000 (02:59 -0700)
InitAddrInfo() and GetAddrInfo() both allocate addrinfo structs which
must be freed by FreeAddrInfo(). Several places in ICMP were not doing
that free step.

 Detected by Coverity Scan. Issues 740434, 740435, 740436, 740437.

src/icmp/Icmp4.cc
src/icmp/Icmp6.cc

index 2aa7a57a098c6d9a8adebb11a0471b26ef1569d3..ffb3c3de73e7092df0ea724d3c20e2ceb6d042ba 100644 (file)
@@ -156,6 +156,7 @@ Icmp4::SendEcho(Ip::Address &to, int opcode, const char *payload, int len)
     }
 
     Log(to, ' ', NULL, 0, 0);
+    to.FreeAddrInfo(S);
 }
 
 void
@@ -221,11 +222,15 @@ Icmp4::Recv(void)
 
     icmp = (struct icmphdr *) (void *) (pkt + iphdrlen);
 
-    if (icmp->icmp_type != ICMP_ECHOREPLY)
+    if (icmp->icmp_type != ICMP_ECHOREPLY) {
+        preply.from.FreeAddrInfo(from);
         return;
+    }
 
-    if (icmp->icmp_id != icmp_ident)
+    if (icmp->icmp_id != icmp_ident) {
+        preply.from.FreeAddrInfo(from);
         return;
+    }
 
     echo = (icmpEchoData *) (void *) (icmp + 1);
 
@@ -242,6 +247,7 @@ Icmp4::Recv(void)
     control.SendResult(preply, (sizeof(pingerReplyData) - MAX_PKT4_SZ + preply.psize) );
 
     Log(preply.from, icmp->icmp_type, icmpPktStr[icmp->icmp_type], preply.rtt, preply.hops);
+    preply.from.FreeAddrInfo(from);
 }
 
 #endif /* USE_ICMP */
index 206df2c8961e61db7a39530057dc0669603850ff..5738e79d5df4bd27969b3d417e4762ef89c1060c 100644 (file)
@@ -202,6 +202,7 @@ Icmp6::SendEcho(Ip::Address &to, int opcode, const char *payload, int len)
     debugs(42,9, HERE << "x=" << x);
 
     Log(to, 0, NULL, 0, 0);
+    to.FreeAddrInfo(S);
 }
 
 /**
@@ -296,11 +297,13 @@ Icmp6::Recv(void)
                    ( icmp6header->icmp6_type&0x80 ? icmp6HighPktStr[(int)(icmp6header->icmp6_type&0x7f)] : icmp6LowPktStr[(int)(icmp6header->icmp6_type&0x7f)] )
                   );
         }
+        preply.from.FreeAddrInfo(from);
         return;
     }
 
     if (icmp6header->icmp6_id != icmp_ident) {
         debugs(42, 8, HERE << "dropping Icmp6 read. IDENT check failed. ident=='" << icmp_ident << "'=='" << icmp6header->icmp6_id << "'");
+        preply.from.FreeAddrInfo(from);
         return;
     }
 
@@ -337,6 +340,7 @@ Icmp6::Recv(void)
 
     /* send results of the lookup back to squid.*/
     control.SendResult(preply, (sizeof(pingerReplyData) - PINGER_PAYLOAD_SZ + preply.psize) );
+    preply.from.FreeAddrInfo(from);
 }
 
 #endif /* USE_ICMP */