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/digits_dots.c b/nss/digits_dots.c
8 index 2b86295..e007ef4 100644
9 --- a/nss/digits_dots.c
10 +++ b/nss/digits_dots.c
11 @@ -46,7 +46,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
14 *h_errnop = NETDB_INTERNAL;
16 + if (buffer_size == NULL)
17 + *status = NSS_STATUS_TRYAGAIN;
23 @@ -83,14 +86,16 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
26 size_needed = (sizeof (*host_addr)
27 - + sizeof (*h_addr_ptrs) + strlen (name) + 1);
28 + + sizeof (*h_addr_ptrs)
29 + + sizeof (*h_alias_ptr) + strlen (name) + 1);
31 if (buffer_size == NULL)
33 if (buflen < size_needed)
35 + *status = NSS_STATUS_TRYAGAIN;
37 - *h_errnop = TRY_AGAIN;
38 + *h_errnop = NETDB_INTERNAL;
42 @@ -109,7 +114,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
46 - *h_errnop = TRY_AGAIN;
47 + *h_errnop = NETDB_INTERNAL;
51 @@ -149,7 +154,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
54 *h_errnop = HOST_NOT_FOUND;
56 + if (buffer_size == NULL)
57 + *status = NSS_STATUS_NOTFOUND;
62 @@ -190,7 +197,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
63 if (buffer_size == NULL)
64 *status = NSS_STATUS_SUCCESS;
71 @@ -201,15 +208,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
73 if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
77 - typedef unsigned char host_addr_t[16];
78 - host_addr_t *host_addr;
79 - typedef char *host_addr_list_t[2];
80 - host_addr_list_t *h_addr_ptrs;
87 @@ -225,7 +223,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
88 /* This is not possible. We cannot represent an IPv6 address
89 in an `struct in_addr' variable. */
90 *h_errnop = HOST_NOT_FOUND;
92 + if (buffer_size == NULL)
93 + *status = NSS_STATUS_NOTFOUND;
99 @@ -233,42 +234,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
103 - size_needed = (sizeof (*host_addr)
104 - + sizeof (*h_addr_ptrs) + strlen (name) + 1);
106 - if (buffer_size == NULL && buflen < size_needed)
108 - if (h_errnop != NULL)
109 - *h_errnop = TRY_AGAIN;
110 - __set_errno (ERANGE);
113 - else if (buffer_size != NULL && *buffer_size < size_needed)
116 - *buffer_size = size_needed;
117 - new_buf = realloc (*buffer, *buffer_size);
119 - if (new_buf == NULL)
123 - __set_errno (save);
132 - memset (*buffer, '\0', size_needed);
134 - host_addr = (host_addr_t *) *buffer;
135 - h_addr_ptrs = (host_addr_list_t *)
136 - ((char *) host_addr + sizeof (*host_addr));
137 - hostname = (char *) h_addr_ptrs + sizeof (*h_addr_ptrs);
139 for (cp = name;; ++cp)
142 @@ -281,7 +246,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
143 if (inet_pton (AF_INET6, name, host_addr) <= 0)
145 *h_errnop = HOST_NOT_FOUND;
147 + if (buffer_size == NULL)
148 + *status = NSS_STATUS_NOTFOUND;
153 diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
154 index 1067744..44d00f4 100644
155 --- a/nss/getXXbyYY_r.c
156 +++ b/nss/getXXbyYY_r.c
157 @@ -179,6 +179,9 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
162 + any_service = true;
167 diff --git a/nss/test-digits-dots.c b/nss/test-digits-dots.c
169 index 0000000..1efa344
171 +++ b/nss/test-digits-dots.c
173 +/* Copyright (C) 2013 Free Software Foundation, Inc.
174 + This file is part of the GNU C Library.
176 + The GNU C Library is free software; you can redistribute it and/or
177 + modify it under the terms of the GNU Lesser General Public
178 + License as published by the Free Software Foundation; either
179 + version 2.1 of the License, or (at your option) any later version.
181 + The GNU C Library is distributed in the hope that it will be useful,
182 + but WITHOUT ANY WARRANTY; without even the implied warranty of
183 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
184 + Lesser General Public License for more details.
186 + You should have received a copy of the GNU Lesser General Public
187 + License along with the GNU C Library; if not, see
188 + <http://www.gnu.org/licenses/>. */
190 +/* Testcase for BZ #15014 */
200 + struct hostent *result = NULL;
201 + struct hostent ret;
205 + err = gethostbyname_r ("1.2.3.4", &ret, buf, sizeof (buf), &result, &h_err);
206 + return err == ERANGE && h_err == NETDB_INTERNAL ? EXIT_SUCCESS : EXIT_FAILURE;
209 +#define TEST_FUNCTION do_test ()
210 +#include "../test-skeleton.c"