Re: [Fwd: [FYI] Important bug fix commited]
Andreas Fink <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
> -----------------------------------------
> Hi List,
>
> just to keep you informed and to let you all to update your live
> Kannel's.
> I have commited important bug fix for gw_gethostbyname function.
> Earlier we
> have just copied a pointer to the new struct hostent , but
> unfortunately it's
> not enough, because glibc use statically allocated buffers for pointers
> stored within struct hostent. So we have a race condition, because
> next call
> to gethostbyname function will overwrite this statically buffer and in
> worst
> case we have SEGFAULT.
> Here is the quote from `man gethostbyname`:
> The functions gethostbyname() and gethostbyaddr() may return
> pointers to static data, which may be overwritten by later
> calls.
> Copying the struct hostent does not suffice, since it contains
> pointers- a deep copy is required.
>
from man gethostbyname on MacOS X:
BUGS
These functions use static data storage; if the data is needed for
future
use, it should be copied before any subsequent calls overwrite it.
Only
the Internet address format is currently understood.
in my eyes it should be sufficient to make a semaphore lock around the
function, copy the data out and you're done.
The struct returned on MacOS X is:
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name
server */
};
and the function calls are:
struct hostent * gethostbyname(const char *name);
struct hostent * gethostbyname2(const char *name, int af);
> Commited version trying to use reentrant alternatives for
> gethostbyname,
> unfortunately it's not a POSIX functions and every OS have a different
> call.
> For now we have 3 types supported:
> 1) 6 params for call (Linux version)
> 2) 5 params for call (Solaris version)
> 3) no reentrant function at all , make a deep copy of hostent
> pointers.
>
> gethostbyname_r with 3 params for call doesn't supported yet (deep copy
> used), because I can't test it (implementation should be simple).
>
> --
> Best regards / Mit besten Grüßen aus Düsseldorf
>
> Dipl.-Ing.
> Alexander Malysh
> ___________________________________________
>
> Centrium GmbH
> Vogelsanger Weg 80
> 40470 Düsseldorf
>
> Fon: +49 (0211) 74 84 51 80
> Fax: +49 (0211) 277 49 109
>
> email: [email protected]
> web: www.centrium.de
> msn: [email protected]
> icq: 98063111
> ___________________________________________
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.fsf.org/philosophy/no-word-attachments.html
>
>
>
>
>
Andreas Fink
Global Networks Switzerland AG
------------------------------------------------------------------
Tel: +41-61-6666333 Fax: +41-61-6666334 Mobile: +41-79-2457333
Global Networks, Inc. Clarastrasse 3, 4058 Basel, Switzerland
Web: http://www.global-networks.ch/ [email protected]
------------------------------------------------------------------