[PATCH] Fix memory leak in _nss_dns_gethostbyname4_r with big DNS answer
Ondřej Bílka
neleai@seznam.cz
Wed Feb 19 12:59:00 GMT 2014
On Tue, Feb 18, 2014 at 03:03:55PM +0100, Andreas Schwab wrote:
> > + /* Check whether ans2p was separately allocated. */
> > + if (host_buffer.buf != orig_host_buffer)
> > + anslen = MAXPACKET;
> > + if (ans2p != NULL
> > + && (ans2p < host_buffer.ptr || ans2p >= host_buffer.ptr + anslen))
> > + free (ans2p);
>
> It turned out that this condition is wrong. send_vc/send_dg can reuse
> the original buffer for the second answer if it fits there, even when
> the first answer didn't, and this may try to free a non-heap pointer.
> So to fix it properly let send_vc/send_dg tell exactly when the buffer
> is newly allocated.
>
Ok, this looks like best solution. Its large but relatively
straighforward patch.
More information about the Libc-alpha
mailing list