[ping] [patch] getaddrinfo bug

Dan Nicolaescu dann at ics.uci.edu
Wed Jan 30 19:53:59 UTC 2008


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;



More information about the uClibc mailing list