|
|
7190b6 |
commit d5dd6189d506068ed11c8bfa1e1e9bffde04decd
|
|
|
7190b6 |
Author: Andreas Schwab <schwab@suse.de>
|
|
|
7190b6 |
Date: Mon Jan 21 17:41:28 2013 +0100
|
|
|
7190b6 |
|
|
|
7190b6 |
Fix parsing of numeric hosts in gethostbyname_r
|
|
|
7190b6 |
|
|
|
12745e |
diff --git glibc-2.17-c758a686/nss/Makefile glibc-2.17-c758a686/nss/Makefile
|
|
|
7190b6 |
index 449a258..553eafa 100644
|
|
|
12745e |
--- glibc-2.17-c758a686/nss/Makefile
|
|
|
12745e |
+++ glibc-2.17-c758a686/nss/Makefile
|
|
|
5de29b |
@@ -37,7 +37,8 @@ install-bin := getent makedb
|
|
|
7190b6 |
makedb-modules = xmalloc hash-string
|
|
|
7190b6 |
extra-objs += $(makedb-modules:=.o)
|
|
|
7190b6 |
|
|
|
f57669 |
-tests = test-netdb tst-nss-test1 bug17079 tst-nss-getpwent
|
|
|
f57669 |
+tests = test-netdb tst-nss-test1 bug17079 tst-nss-getpwent \
|
|
|
5de29b |
+ test-digits-dots
|
|
|
7190b6 |
xtests = bug-erange
|
|
|
7190b6 |
|
|
|
7190b6 |
include ../Makeconfig
|
|
|
12745e |
diff --git glibc-2.17-c758a686/nss/digits_dots.c glibc-2.17-c758a686/nss/digits_dots.c
|
|
|
7190b6 |
index 2b86295..e007ef4 100644
|
|
|
12745e |
--- glibc-2.17-c758a686/nss/digits_dots.c
|
|
|
12745e |
+++ glibc-2.17-c758a686/nss/digits_dots.c
|
|
|
7190b6 |
@@ -46,7 +46,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
{
|
|
|
7190b6 |
if (h_errnop)
|
|
|
7190b6 |
*h_errnop = NETDB_INTERNAL;
|
|
|
7190b6 |
- *result = NULL;
|
|
|
7190b6 |
+ if (buffer_size == NULL)
|
|
|
7190b6 |
+ *status = NSS_STATUS_TRYAGAIN;
|
|
|
7190b6 |
+ else
|
|
|
7190b6 |
+ *result = NULL;
|
|
|
7190b6 |
return -1;
|
|
|
7190b6 |
}
|
|
|
7190b6 |
|
|
|
7190b6 |
@@ -83,14 +86,16 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
}
|
|
|
7190b6 |
|
|
|
7190b6 |
size_needed = (sizeof (*host_addr)
|
|
|
7190b6 |
- + sizeof (*h_addr_ptrs) + strlen (name) + 1);
|
|
|
7190b6 |
+ + sizeof (*h_addr_ptrs)
|
|
|
7190b6 |
+ + sizeof (*h_alias_ptr) + strlen (name) + 1);
|
|
|
7190b6 |
|
|
|
7190b6 |
if (buffer_size == NULL)
|
|
|
7190b6 |
{
|
|
|
7190b6 |
if (buflen < size_needed)
|
|
|
7190b6 |
{
|
|
|
7190b6 |
+ *status = NSS_STATUS_TRYAGAIN;
|
|
|
7190b6 |
if (h_errnop != NULL)
|
|
|
7190b6 |
- *h_errnop = TRY_AGAIN;
|
|
|
7190b6 |
+ *h_errnop = NETDB_INTERNAL;
|
|
|
7190b6 |
__set_errno (ERANGE);
|
|
|
7190b6 |
goto done;
|
|
|
7190b6 |
}
|
|
|
7190b6 |
@@ -109,7 +114,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
*buffer_size = 0;
|
|
|
7190b6 |
__set_errno (save);
|
|
|
7190b6 |
if (h_errnop != NULL)
|
|
|
7190b6 |
- *h_errnop = TRY_AGAIN;
|
|
|
7190b6 |
+ *h_errnop = NETDB_INTERNAL;
|
|
|
7190b6 |
*result = NULL;
|
|
|
7190b6 |
goto done;
|
|
|
7190b6 |
}
|
|
|
7190b6 |
@@ -149,7 +154,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
if (! ok)
|
|
|
7190b6 |
{
|
|
|
7190b6 |
*h_errnop = HOST_NOT_FOUND;
|
|
|
7190b6 |
- if (buffer_size)
|
|
|
7190b6 |
+ if (buffer_size == NULL)
|
|
|
7190b6 |
+ *status = NSS_STATUS_NOTFOUND;
|
|
|
7190b6 |
+ else
|
|
|
7190b6 |
*result = NULL;
|
|
|
7190b6 |
goto done;
|
|
|
7190b6 |
}
|
|
|
7190b6 |
@@ -190,7 +197,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
if (buffer_size == NULL)
|
|
|
7190b6 |
*status = NSS_STATUS_SUCCESS;
|
|
|
7190b6 |
else
|
|
|
7190b6 |
- *result = resbuf;
|
|
|
7190b6 |
+ *result = resbuf;
|
|
|
7190b6 |
goto done;
|
|
|
7190b6 |
}
|
|
|
7190b6 |
|
|
|
7190b6 |
@@ -201,15 +208,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
|
|
|
7190b6 |
if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
|
|
|
7190b6 |
{
|
|
|
7190b6 |
- const char *cp;
|
|
|
7190b6 |
- char *hostname;
|
|
|
7190b6 |
- typedef unsigned char host_addr_t[16];
|
|
|
7190b6 |
- host_addr_t *host_addr;
|
|
|
7190b6 |
- typedef char *host_addr_list_t[2];
|
|
|
7190b6 |
- host_addr_list_t *h_addr_ptrs;
|
|
|
7190b6 |
- size_t size_needed;
|
|
|
7190b6 |
- int addr_size;
|
|
|
7190b6 |
-
|
|
|
7190b6 |
switch (af)
|
|
|
7190b6 |
{
|
|
|
7190b6 |
default:
|
|
|
7190b6 |
@@ -225,7 +223,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
/* This is not possible. We cannot represent an IPv6 address
|
|
|
7190b6 |
in an `struct in_addr' variable. */
|
|
|
7190b6 |
*h_errnop = HOST_NOT_FOUND;
|
|
|
7190b6 |
- *result = NULL;
|
|
|
7190b6 |
+ if (buffer_size == NULL)
|
|
|
7190b6 |
+ *status = NSS_STATUS_NOTFOUND;
|
|
|
7190b6 |
+ else
|
|
|
7190b6 |
+ *result = NULL;
|
|
|
7190b6 |
goto done;
|
|
|
7190b6 |
|
|
|
7190b6 |
case AF_INET6:
|
|
|
7190b6 |
@@ -233,42 +234,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
break;
|
|
|
7190b6 |
}
|
|
|
7190b6 |
|
|
|
7190b6 |
- size_needed = (sizeof (*host_addr)
|
|
|
7190b6 |
- + sizeof (*h_addr_ptrs) + strlen (name) + 1);
|
|
|
7190b6 |
-
|
|
|
7190b6 |
- if (buffer_size == NULL && buflen < size_needed)
|
|
|
7190b6 |
- {
|
|
|
7190b6 |
- if (h_errnop != NULL)
|
|
|
7190b6 |
- *h_errnop = TRY_AGAIN;
|
|
|
7190b6 |
- __set_errno (ERANGE);
|
|
|
7190b6 |
- goto done;
|
|
|
7190b6 |
- }
|
|
|
7190b6 |
- else if (buffer_size != NULL && *buffer_size < size_needed)
|
|
|
7190b6 |
- {
|
|
|
7190b6 |
- char *new_buf;
|
|
|
7190b6 |
- *buffer_size = size_needed;
|
|
|
7190b6 |
- new_buf = realloc (*buffer, *buffer_size);
|
|
|
7190b6 |
-
|
|
|
7190b6 |
- if (new_buf == NULL)
|
|
|
7190b6 |
- {
|
|
|
7190b6 |
- save = errno;
|
|
|
7190b6 |
- free (*buffer);
|
|
|
7190b6 |
- __set_errno (save);
|
|
|
7190b6 |
- *buffer = NULL;
|
|
|
7190b6 |
- *buffer_size = 0;
|
|
|
7190b6 |
- *result = NULL;
|
|
|
7190b6 |
- goto done;
|
|
|
7190b6 |
- }
|
|
|
7190b6 |
- *buffer = new_buf;
|
|
|
7190b6 |
- }
|
|
|
7190b6 |
-
|
|
|
7190b6 |
- memset (*buffer, '\0', size_needed);
|
|
|
7190b6 |
-
|
|
|
7190b6 |
- host_addr = (host_addr_t *) *buffer;
|
|
|
7190b6 |
- h_addr_ptrs = (host_addr_list_t *)
|
|
|
7190b6 |
- ((char *) host_addr + sizeof (*host_addr));
|
|
|
7190b6 |
- hostname = (char *) h_addr_ptrs + sizeof (*h_addr_ptrs);
|
|
|
7190b6 |
-
|
|
|
7190b6 |
for (cp = name;; ++cp)
|
|
|
7190b6 |
{
|
|
|
7190b6 |
if (!*cp)
|
|
|
7190b6 |
@@ -281,7 +246,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
|
|
|
7190b6 |
if (inet_pton (AF_INET6, name, host_addr) <= 0)
|
|
|
7190b6 |
{
|
|
|
7190b6 |
*h_errnop = HOST_NOT_FOUND;
|
|
|
7190b6 |
- if (buffer_size)
|
|
|
7190b6 |
+ if (buffer_size == NULL)
|
|
|
7190b6 |
+ *status = NSS_STATUS_NOTFOUND;
|
|
|
7190b6 |
+ else
|
|
|
7190b6 |
*result = NULL;
|
|
|
7190b6 |
goto done;
|
|
|
7190b6 |
}
|
|
|
12745e |
diff --git glibc-2.17-c758a686/nss/getXXbyYY_r.c glibc-2.17-c758a686/nss/getXXbyYY_r.c
|
|
|
7190b6 |
index 1067744..44d00f4 100644
|
|
|
12745e |
--- glibc-2.17-c758a686/nss/getXXbyYY_r.c
|
|
|
12745e |
+++ glibc-2.17-c758a686/nss/getXXbyYY_r.c
|
|
|
7190b6 |
@@ -179,6 +179,9 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
|
|
|
7190b6 |
case -1:
|
|
|
7190b6 |
return errno;
|
|
|
7190b6 |
case 1:
|
|
|
7190b6 |
+#ifdef NEED_H_ERRNO
|
|
|
7190b6 |
+ any_service = true;
|
|
|
7190b6 |
+#endif
|
|
|
7190b6 |
goto done;
|
|
|
7190b6 |
}
|
|
|
7190b6 |
#endif
|
|
|
7190b6 |
@@ -288,7 +291,7 @@ done:
|
|
|
7190b6 |
/* This happens when we weren't able to use a service for reasons other
|
|
|
7190b6 |
than the module not being found. In such a case, we'd want to tell the
|
|
|
7190b6 |
caller that errno has the real reason for failure. */
|
|
|
7190b6 |
- *h_errnop = NETDB_INTERNAL;
|
|
|
7190b6 |
+ *h_errnop = NETDB_INTERNAL;
|
|
|
7190b6 |
else if (status != NSS_STATUS_SUCCESS && !any_service)
|
|
|
7190b6 |
/* We were not able to use any service. */
|
|
|
7190b6 |
*h_errnop = NO_RECOVERY;
|
|
|
12745e |
diff --git glibc-2.17-c758a686/nss/test-digits-dots.c glibc-2.17-c758a686/nss/test-digits-dots.c
|
|
|
7190b6 |
new file mode 100644
|
|
|
7190b6 |
index 0000000..1efa344
|
|
|
7190b6 |
--- /dev/null
|
|
|
12745e |
+++ glibc-2.17-c758a686/nss/test-digits-dots.c
|
|
|
7190b6 |
@@ -0,0 +1,38 @@
|
|
|
7190b6 |
+/* Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
7190b6 |
+ This file is part of the GNU C Library.
|
|
|
7190b6 |
+
|
|
|
7190b6 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
7190b6 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
7190b6 |
+ License as published by the Free Software Foundation; either
|
|
|
7190b6 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
7190b6 |
+
|
|
|
7190b6 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
7190b6 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7190b6 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
7190b6 |
+ Lesser General Public License for more details.
|
|
|
7190b6 |
+
|
|
|
7190b6 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
7190b6 |
+ License along with the GNU C Library; if not, see
|
|
|
7190b6 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
7190b6 |
+
|
|
|
7190b6 |
+/* Testcase for BZ #15014 */
|
|
|
7190b6 |
+
|
|
|
7190b6 |
+#include <stdlib.h>
|
|
|
7190b6 |
+#include <netdb.h>
|
|
|
7190b6 |
+#include <errno.h>
|
|
|
7190b6 |
+
|
|
|
7190b6 |
+static int
|
|
|
7190b6 |
+do_test (void)
|
|
|
7190b6 |
+{
|
|
|
7190b6 |
+ char buf[32];
|
|
|
7190b6 |
+ struct hostent *result = NULL;
|
|
|
7190b6 |
+ struct hostent ret;
|
|
|
7190b6 |
+ int h_err = 0;
|
|
|
7190b6 |
+ int err;
|
|
|
7190b6 |
+
|
|
|
7190b6 |
+ err = gethostbyname_r ("1.2.3.4", &ret, buf, sizeof (buf), &result, &h_err);
|
|
|
7190b6 |
+ return err == ERANGE && h_err == NETDB_INTERNAL ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
7190b6 |
+}
|
|
|
7190b6 |
+
|
|
|
7190b6 |
+#define TEST_FUNCTION do_test ()
|
|
|
7190b6 |
+#include "../test-skeleton.c"
|