[ping] [patch] getaddrinfo bug
Filippo ARCIDIACONO
filippo.arcidiacono at st.com
Thu Feb 7 16:29:32 UTC 2008
> -----Original Message-----
> From: uclibc-bounces at uclibc.org
> [mailto:uclibc-bounces at uclibc.org] On Behalf Of Dan Nicolaescu
> Sent: Wednesday, January 30, 2008 8:54 PM
> To: uclibc at uclibc.org
> Subject: [ping] [patch] getaddrinfo bug
>
> 2 weeks ago I sent this patch. There was no feedback on it.
>
> Can someone please take a look and comment on this patch?
>
> Thanks
> --dan
>
>
>
> When using x11r7, starting X11 application ends up calling
> _xcb_open_tcp in libxcb.
>
> _xcb_open_tcp looks like this:
>
> static int _xcb_open_tcp(char *host, const unsigned short port) {
> int fd = -1;
> struct addrinfo hints = { AI_ADDRCONFIG #ifdef AI_NUMERICSERV
> | AI_NUMERICSERV #endif
> , AF_UNSPEC, SOCK_STREAM }; [snip]
> res = getaddrinfo(host, service, &hints, &results);
>
>
> uclibc's netdb.h always defines AI_NUMERICSERV, so
> AI_NUMERICSERV is always used.
>
> The getaddrinfo implementation in uclibc does:
>
> if (hints->ai_flags & ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST|
> AI_ADDRCONFIG|AI_V4MAPPED|AI_ALL))
> return EAI_BADFLAGS;
>
> which means that getaddrinfo will always fail and return
> EAI_BADFLAGS because it passes AI_NUMERICSERV.
>
> As a result, X11 applications won't start.
>
> This patch fixes the problem:
>
> --- getaddrinfo.c.orig 2008-01-15 07:36:08.264317000 -0800
> +++ getaddrinfo.c 2008-01-15 07:36:00.518071000 -0800
> @@ -822,7 +822,7 @@
> if (hints == NULL)
> hints = &default_hints;
>
> - if (hints->ai_flags & ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST|
> + if (hints->ai_flags &
> + ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST|AI_NUMERICSERV|
> AI_ADDRCONFIG|AI_V4MAPPED|AI_ALL))
> return EAI_BADFLAGS;
In my opinion you have to check if the string is not just a number
with AI_NUMERICSERV flag high.
See the patch below.
For more detail see glibc patch
http://sourceware.org/ml/glibc-cvs/2004-q3/msg00296.html
Based on the following bug
http://sources.redhat.com/bugzilla/show_bug.cgi?id=296
Regards
Filippo Arcidiacono.
--- uClibc-nptl/libc/inet/getaddrinfo.c (revision 16)
+++ uClibc-nptl/libc/inet/getaddrinfo.c (working copy)
@@ -823,7 +823,7 @@
hints = &default_hints;
if (hints->ai_flags & ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST|
- AI_ADDRCONFIG|AI_V4MAPPED|AI_ALL))
+
AI_ADDRCONFIG|AI_V4MAPPED|AI_NUMERICSERV|AI_ALL))
return EAI_BADFLAGS;
if ((hints->ai_flags & AI_CANONNAME) && name == NULL)
@@ -834,8 +834,12 @@
char *c;
gaih_service.name = service;
gaih_service.num = strtoul (gaih_service.name, &c, 10);
- if (*c)
+ if (*c != '\0') {
+ if (hints->ai_flags & AI_NUMERICSERV)
+ return EAI_NONAME;
+
gaih_service.num = -1;
+ }
else
/*
* Can't specify a numerical socket unless a protocol
> _______________________________________________
> uClibc mailing list
> uClibc at uclibc.org
> http://busybox.net/cgi-bin/mailman/listinfo/uclibc
>
More information about the uClibc
mailing list