[PATCH] gethostbyname segfault

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] gethostbyname segfault

Vincent CHAVANIS
This fixes the segfault i had,

when tried to connect bearbox on X86_64SMP and DNS SERVERS IPV6 compatible.
gethostbyname2() works like gethostbyname(), but permits to specify the address family (AF_INET) to which the address must belong.
Glibc2 also has reentrant versions gethostbyname_r() and gethostbyname2_r().


--- /cvs/gateway/gwlib/protected.c 2005-02-11 16:35:48.000000000 +0100
+++ /gateway/gwlib/protected.c 2006-02-23 14:00:23.000000000 +0100
@@ -193,7 +193,7 @@
 
     bufflen = 1024;
     *buff = (char*) gw_malloc(bufflen);
-    while ((res=gethostbyname_r(name, &hp,*buff, bufflen, &tmphp, &herr)) == ERANGE) {
+    while ((res=gethostbyname2_r(name, AF_INET,&hp,*buff, bufflen, &tmphp, &herr)) == ERANGE) {
         /* enlarge the buffer */
        bufflen *= 2;
        *buff = (char*) gw_realloc(*buff, bufflen);


--
Telemaque - NICE - (FR)
Service Technique - Developpement
http://www.telemaque.fr/
[hidden email]
Tel : +33 4 93 97 71 64 (fax 68)

x86_64_gehostbyname.patch.txt (563 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] gethostbyname segfault

Stipe Tolj
Vincent CHAVANIS wrote:

> This fixes the segfault i had,
>
> when tried to connect bearbox on X86_64SMP and DNS SERVERS IPV6 compatible.
> gethostbyname2() works like gethostbyname(), but permits to specify the address family (AF_INET) to which the address must belong.
> Glibc2 also has reentrant versions gethostbyname_r() and gethostbyname2_r().
>
>
> --- /cvs/gateway/gwlib/protected.c 2005-02-11 16:35:48.000000000 +0100
> +++ /gateway/gwlib/protected.c 2006-02-23 14:00:23.000000000 +0100
> @@ -193,7 +193,7 @@
>  
>      bufflen = 1024;
>      *buff = (char*) gw_malloc(bufflen);
> -    while ((res=gethostbyname_r(name, &hp,*buff, bufflen, &tmphp, &herr)) == ERANGE) {
> +    while ((res=gethostbyname2_r(name, AF_INET,&hp,*buff, bufflen, &tmphp, &herr)) == ERANGE) {
>          /* enlarge the buffer */
>         bufflen *= 2;
>         *buff = (char*) gw_realloc(*buff, bufflen);
>

Thanks for the patch Vincent.

Actually gethostbyname2() should be avoided IMO if no IPv6 build is done. So the
question is, why does the response of the IPv6 eanbled DNS server break our
regular IPv4 gethostbyname_r()?

AFAIS, the usage of gethostbyname2() is suggested to be avoided, since it's
"only" a GNU extension, but no official API call.

Any comments from the others? I'm +-0 on commiting this, in terms of a clean
resolving via autoconf detection macro and gw-config.h.in #define.

Stipe

-------------------------------------------------------------------
Kölner Landstrasse 419
40589 Düsseldorf, NRW, Germany

tolj.org system architecture      Kannel Software Foundation (KSF)
http://www.tolj.org/              http://www.kannel.org/

mailto:st_{at}_tolj.org           mailto:stolj_{at}_kannel.org
-------------------------------------------------------------------