------------------------------------------------------------ revno: 12449 revision-id: squid3@treenet.co.nz-20130109001944-s5yj42ks727ibr6d parent: squid3@treenet.co.nz-20130109001202-xx9pa0oujcpvw072 committer: Amos Jeffries branch nick: 3.3 timestamp: Tue 2013-01-08 17:19:44 -0700 message: Fix memory leaks in ICMP 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. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20130109001944-s5yj42ks727ibr6d # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # testament_sha1: 4cc5b81be797cd480dd40b909bc4069ff5192906 # timestamp: 2013-01-09 00:54:30 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # base_revision_id: squid3@treenet.co.nz-20130109001202-\ # xx9pa0oujcpvw072 # # Begin patch === modified file 'src/icmp/Icmp4.cc' --- src/icmp/Icmp4.cc 2012-09-01 14:38:36 +0000 +++ src/icmp/Icmp4.cc 2013-01-09 00:19:44 +0000 @@ -155,6 +155,7 @@ } Log(to, ' ', NULL, 0, 0); + to.FreeAddrInfo(S); } void @@ -220,11 +221,15 @@ 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); @@ -241,6 +246,7 @@ 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 */ === modified file 'src/icmp/Icmp6.cc' --- src/icmp/Icmp6.cc 2012-09-01 14:38:36 +0000 +++ src/icmp/Icmp6.cc 2013-01-09 00:19:44 +0000 @@ -200,6 +200,7 @@ debugs(42,9, HERE << "x=" << x); Log(to, 0, NULL, 0, 0); + to.FreeAddrInfo(S); } /** @@ -293,11 +294,13 @@ ( 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; } @@ -334,6 +337,7 @@ /* 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 */