1 commit d5dd6189d506068ed11c8bfa1e1e9bffde04decd
2 Author: Andreas Schwab <schwab@suse.de>
3 Date: Mon Jan 21 17:41:28 2013 +0100
5 Fix parsing of numeric hosts in gethostbyname_r
7 diff --git a/nss/Makefile b/nss/Makefile
8 index 449a258..553eafa 100644
11 @@ -37,7 +37,7 @@ install-bin := getent makedb
15 -tests = test-netdb tst-nss-test1
16 +tests = test-netdb tst-nss-test1 test-digits-dots
20 diff --git a/nss/digits_dots.c b/nss/digits_dots.c
21 index 2b86295..e007ef4 100644
22 --- a/nss/digits_dots.c
23 +++ b/nss/digits_dots.c
24 @@ -46,7 +46,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
27 *h_errnop = NETDB_INTERNAL;
29 + if (buffer_size == NULL)
30 + *status = NSS_STATUS_TRYAGAIN;
36 @@ -83,14 +86,16 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
39 size_needed = (sizeof (*host_addr)
40 - + sizeof (*h_addr_ptrs) + strlen (name) + 1);
41 + + sizeof (*h_addr_ptrs)
42 + + sizeof (*h_alias_ptr) + strlen (name) + 1);
44 if (buffer_size == NULL)
46 if (buflen < size_needed)
48 + *status = NSS_STATUS_TRYAGAIN;
50 - *h_errnop = TRY_AGAIN;
51 + *h_errnop = NETDB_INTERNAL;
55 @@ -109,7 +114,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
59 - *h_errnop = TRY_AGAIN;
60 + *h_errnop = NETDB_INTERNAL;
64 @@ -149,7 +154,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
67 *h_errnop = HOST_NOT_FOUND;
69 + if (buffer_size == NULL)
70 + *status = NSS_STATUS_NOTFOUND;
75 @@ -190,7 +197,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
76 if (buffer_size == NULL)
77 *status = NSS_STATUS_SUCCESS;
84 @@ -201,15 +208,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
86 if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
90 - typedef unsigned char host_addr_t[16];
91 - host_addr_t *host_addr;
92 - typedef char *host_addr_list_t[2];
93 - host_addr_list_t *h_addr_ptrs;
100 @@ -225,7 +223,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
101 /* This is not possible. We cannot represent an IPv6 address
102 in an `struct in_addr' variable. */
103 *h_errnop = HOST_NOT_FOUND;
105 + if (buffer_size == NULL)
106 + *status = NSS_STATUS_NOTFOUND;
112 @@ -233,42 +234,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
116 - size_needed = (sizeof (*host_addr)
117 - + sizeof (*h_addr_ptrs) + strlen (name) + 1);
119 - if (buffer_size == NULL && buflen < size_needed)
121 - if (h_errnop != NULL)
122 - *h_errnop = TRY_AGAIN;
123 - __set_errno (ERANGE);
126 - else if (buffer_size != NULL && *buffer_size < size_needed)
129 - *buffer_size = size_needed;
130 - new_buf = realloc (*buffer, *buffer_size);
132 - if (new_buf == NULL)
136 - __set_errno (save);
145 - memset (*buffer, '\0', size_needed);
147 - host_addr = (host_addr_t *) *buffer;
148 - h_addr_ptrs = (host_addr_list_t *)
149 - ((char *) host_addr + sizeof (*host_addr));
150 - hostname = (char *) h_addr_ptrs + sizeof (*h_addr_ptrs);
152 for (cp = name;; ++cp)
155 @@ -281,7 +246,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
156 if (inet_pton (AF_INET6, name, host_addr) <= 0)
158 *h_errnop = HOST_NOT_FOUND;
160 + if (buffer_size == NULL)
161 + *status = NSS_STATUS_NOTFOUND;
166 diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
167 index 1067744..44d00f4 100644
168 --- a/nss/getXXbyYY_r.c
169 +++ b/nss/getXXbyYY_r.c
170 @@ -179,6 +179,9 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
175 + any_service = true;
180 diff --git a/nss/test-digits-dots.c b/nss/test-digits-dots.c
182 index 0000000..1efa344
184 +++ b/nss/test-digits-dots.c
186 +/* Copyright (C) 2013 Free Software Foundation, Inc.
187 + This file is part of the GNU C Library.
189 + The GNU C Library is free software; you can redistribute it and/or
190 + modify it under the terms of the GNU Lesser General Public
191 + License as published by the Free Software Foundation; either
192 + version 2.1 of the License, or (at your option) any later version.
194 + The GNU C Library is distributed in the hope that it will be useful,
195 + but WITHOUT ANY WARRANTY; without even the implied warranty of
196 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
197 + Lesser General Public License for more details.
199 + You should have received a copy of the GNU Lesser General Public
200 + License along with the GNU C Library; if not, see
201 + <http://www.gnu.org/licenses/>. */
203 +/* Testcase for BZ #15014 */
213 + struct hostent *result = NULL;
214 + struct hostent ret;
218 + err = gethostbyname_r ("1.2.3.4", &ret, buf, sizeof (buf), &result, &h_err);
219 + return err == ERANGE && h_err == NETDB_INTERNAL ? EXIT_SUCCESS : EXIT_FAILURE;
222 +#define TEST_FUNCTION do_test ()
223 +#include "../test-skeleton.c"