patching file inet/getnameinfo.c Hunk #1 FAILED at 83. Hunk #2 FAILED at 180. Hunk #3 succeeded at 277 (offset -8 lines). 2 out of 3 hunks FAILED -- saving rejects to file inet/getnameinfo.c.rej Reject file inet/getnameinfo.c.rej: --- inet/getnameinfo.c +++ inet/getnameinfo.c @@ -83,94 +83,95 @@ libc_freeres_ptr (static char *domain); now ignored. */ #define DEPRECATED_NI_IDN 192 -static void +static bool nrl_domainname_core (struct scratch_buffer *tmpbuf) { char *c; struct hostent *h, th; int herror; - while (__gethostbyname_r ("localhost", &th, - tmpbuf->data, tmpbuf->length, + while (__gethostbyname_r ("localhost", &th, tmpbuf->data, tmpbuf->length, &h, &herror)) { if (herror == NETDB_INTERNAL && errno == ERANGE) { if (!scratch_buffer_grow (tmpbuf)) - return; + return false; } else break; } if (h != NULL && (c = strchr (h->h_name, '.')) != NULL) - domain = __strdup (++c); - else { - /* The name contains no domain information. Use the name - now to get more information. */ - while (__gethostname (tmpbuf->data, tmpbuf->length)) - if (!scratch_buffer_grow (tmpbuf)) - return; - - if ((c = strchr (tmpbuf->data, '.')) != NULL) - domain = __strdup (++c); - else - { - /* We need to preserve the hostname. */ - size_t hstnamelen = strlen (tmpbuf->data) + 1; - while (__gethostbyname_r (tmpbuf->data, &th, - tmpbuf->data + hstnamelen, - tmpbuf->length - hstnamelen, - &h, &herror)) - { - if (herror == NETDB_INTERNAL && errno == ERANGE) - { - if (!scratch_buffer_grow_preserve (tmpbuf)) - return; - } - else - break; - } + domain = __strdup (++c); + return domain != NULL; + } - if (h != NULL && (c = strchr(h->h_name, '.')) != NULL) - domain = __strdup (++c); - else - { - struct in_addr in_addr; + /* The name contains no domain information. Use the name + now to get more information. */ + while (__gethostname (tmpbuf->data, tmpbuf->length)) + if (!scratch_buffer_grow (tmpbuf)) + return false; - in_addr.s_addr = htonl (INADDR_LOOPBACK); + if ((c = strchr (tmpbuf->data, '.')) != NULL) + { + domain = __strdup (++c); + return domain != NULL; + } - while (__gethostbyaddr_r ((const char *) &in_addr, - sizeof (struct in_addr), - AF_INET, &th, - tmpbuf->data, - tmpbuf->length, - &h, &herror)) - { - if (herror == NETDB_INTERNAL && errno == ERANGE) - { - if (!scratch_buffer_grow (tmpbuf)) - return; - } - else - break; - } + /* We need to preserve the hostname. */ + size_t hstnamelen = strlen (tmpbuf->data) + 1; + while (__gethostbyname_r (tmpbuf->data, &th, tmpbuf->data + hstnamelen, + tmpbuf->length - hstnamelen, &h, &herror)) + { + if (herror == NETDB_INTERNAL && errno == ERANGE) + { + if (!scratch_buffer_grow_preserve (tmpbuf)) + return false; + } + else + break; + } - if (h != NULL && (c = strchr (h->h_name, '.')) != NULL) - domain = __strdup (++c); - } + if (h != NULL && (c = strchr(h->h_name, '.')) != NULL) + { + domain = __strdup (++c); + return domain != NULL; + } + + struct in_addr in_addr = { .s_addr = htonl (INADDR_LOOPBACK) }; + + while (__gethostbyaddr_r ((const char *) &in_addr, sizeof (struct in_addr), + AF_INET, &th, tmpbuf->data, tmpbuf->length, &h, + &herror)) + { + if (herror == NETDB_INTERNAL && errno == ERANGE) + { + if (!scratch_buffer_grow (tmpbuf)) + return false; } + else + break; + } + + if (h != NULL && (c = strchr (h->h_name, '.')) != NULL) + { + domain = __strdup (++c); + return domain != NULL; } + return true; } -static char * +static bool nrl_domainname (void) { static int not_first; if (__glibc_likely (atomic_load_acquire (¬_first) != 0)) - return domain; + return true; + + int r = true; __libc_lock_define_initialized (static, lock); __libc_lock_lock (lock); @@ -180,16 +181,15 @@ nrl_domainname (void) struct scratch_buffer tmpbuf; scratch_buffer_init (&tmpbuf); - nrl_domainname_core (&tmpbuf); + if ((r = nrl_domainname_core (&tmpbuf))) + atomic_store_release (¬_first, 1); scratch_buffer_free (&tmpbuf); - - atomic_store_release (¬_first, 1); } __libc_lock_unlock (lock); - return domain; + return r; }; /* Copy a string to a destination buffer with length checking. Return