freeradius-client wrapping gethostby*

Alex Massover alex at jajah.com
Mon Mar 8 19:29:37 CET 2010


Hi,

In freeradius-client gethostby* is wrapped in order to be thread-safe. But imho it's done in wrong way causing gethostby* to malfunction.

In lib/ip_util.c:
_______________________________________________
	size_t	hostbuflen;
	char	*tmphostbuf;
	int	res;
	int	herr;
	
	hostbuflen = 1024;
	tmphostbuf = malloc(hostbuflen);
#endif
#endif

#ifdef GETHOSTBYNAME_R
#if defined (GETHOSTBYNAMERSTYLE_GNU)
	while ((res = gethostbyname_r(hostname, &hostbuf, tmphostbuf, hostbuflen, &hp, &herr)) == ERANGE)
	{
		/* Enlarge the buffer */
		hostbuflen *= 2;
		tmphostbuf = realloc(tmphostbuf, hostbuflen);
	}
	free(tmphostbuf);   
_______________________________________________


Afaik if tmphostbuf is freed the data is gone.

The easiest way to fix it which I can think of is thread local storage (TLS), please see the patch.

--
Best Regards,
Alex Massover
VoIP R&D TL
Jajah Inc.



This mail was sent via Mail-SeCure System.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: ip_util.patch
Type: application/octet-stream
Size: 1909 bytes
Desc: ip_util.patch
URL: <http://lists.freeradius.org/pipermail/freeradius-devel/attachments/20100308/62d1fdf3/attachment.obj>


More information about the Freeradius-Devel mailing list