1
From: Andreas Schwab <schwab@suse.de>
2
Date: Mon, 21 Jan 2013 16:41:28 +0000 (+0100)
3
Subject: Fix parsing of numeric hosts in gethostbyname_r
4
X-Git-Tag: glibc-2.18~221
5
X-Git-Url: https://sourceware.org/git/?p=glibc.git;a=commitdiff_plain;h=d5dd6189d506068ed11c8bfa1e1e9bffde04decd
7
Fix parsing of numeric hosts in gethostbyname_r
9
2013-05-21 Andreas Schwab <schwab@suse.de>
12
* nss/getXXbyYY_r.c (INTERNAL (REENTRANT_NAME))
13
[HANDLE_DIGITS_DOTS]: Set any_service when digits-dots parsing was
15
* nss/digits_dots.c (__nss_hostname_digits_dots): Remove
16
redundant variable declarations and reallocation of buffer when
17
parsing as IPv6 address. Always set NSS status when called from
18
reentrant functions. Use NETDB_INTERNAL instead of TRY_AGAIN when
19
buffer too small. Correct computation of needed size.
20
* nss/Makefile (tests): Add test-digits-dots.
21
* nss/test-digits-dots.c: New test.
25
(Ubuntu note: patch differs from upstream commit in that it drops
26
the changelog and NEWS entries as well as the whitespace only change to
27
nss/getXXbyYY_r.c to reduce patch conflicts. --sbeattie)
31
nss/digits_dots.c | 73 +++++++++++++------------------------------------
32
nss/getXXbyYY_r.c | 3 ++
33
nss/test-digits-dots.c | 38 +++++++++++++++++++++++++
34
4 files changed, 62 insertions(+), 54 deletions(-)
36
Index: b/nss/digits_dots.c
37
===================================================================
38
--- a/nss/digits_dots.c
39
+++ b/nss/digits_dots.c
40
@@ -47,7 +47,10 @@ __nss_hostname_digits_dots (const char *
43
*h_errnop = NETDB_INTERNAL;
45
+ if (buffer_size == NULL)
46
+ *status = NSS_STATUS_TRYAGAIN;
52
@@ -84,14 +87,16 @@ __nss_hostname_digits_dots (const char *
55
size_needed = (sizeof (*host_addr)
56
- + sizeof (*h_addr_ptrs) + strlen (name) + 1);
57
+ + sizeof (*h_addr_ptrs)
58
+ + sizeof (*h_alias_ptr) + strlen (name) + 1);
60
if (buffer_size == NULL)
62
if (buflen < size_needed)
64
+ *status = NSS_STATUS_TRYAGAIN;
66
- *h_errnop = TRY_AGAIN;
67
+ *h_errnop = NETDB_INTERNAL;
71
@@ -110,7 +115,7 @@ __nss_hostname_digits_dots (const char *
75
- *h_errnop = TRY_AGAIN;
76
+ *h_errnop = NETDB_INTERNAL;
80
@@ -150,7 +155,9 @@ __nss_hostname_digits_dots (const char *
83
*h_errnop = HOST_NOT_FOUND;
85
+ if (buffer_size == NULL)
86
+ *status = NSS_STATUS_NOTFOUND;
91
@@ -191,7 +198,7 @@ __nss_hostname_digits_dots (const char *
92
if (buffer_size == NULL)
93
*status = NSS_STATUS_SUCCESS;
100
@@ -202,15 +209,6 @@ __nss_hostname_digits_dots (const char *
102
if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
106
- typedef unsigned char host_addr_t[16];
107
- host_addr_t *host_addr;
108
- typedef char *host_addr_list_t[2];
109
- host_addr_list_t *h_addr_ptrs;
110
- size_t size_needed;
116
@@ -226,7 +224,10 @@ __nss_hostname_digits_dots (const char *
117
/* This is not possible. We cannot represent an IPv6 address
118
in an `struct in_addr' variable. */
119
*h_errnop = HOST_NOT_FOUND;
121
+ if (buffer_size == NULL)
122
+ *status = NSS_STATUS_NOTFOUND;
128
@@ -234,42 +235,6 @@ __nss_hostname_digits_dots (const char *
132
- size_needed = (sizeof (*host_addr)
133
- + sizeof (*h_addr_ptrs) + strlen (name) + 1);
135
- if (buffer_size == NULL && buflen < size_needed)
137
- if (h_errnop != NULL)
138
- *h_errnop = TRY_AGAIN;
139
- __set_errno (ERANGE);
142
- else if (buffer_size != NULL && *buffer_size < size_needed)
145
- *buffer_size = size_needed;
146
- new_buf = realloc (*buffer, *buffer_size);
148
- if (new_buf == NULL)
152
- __set_errno (save);
161
- memset (*buffer, '\0', size_needed);
163
- host_addr = (host_addr_t *) *buffer;
164
- h_addr_ptrs = (host_addr_list_t *)
165
- ((char *) host_addr + sizeof (*host_addr));
166
- hostname = (char *) h_addr_ptrs + sizeof (*h_addr_ptrs);
168
for (cp = name;; ++cp)
171
@@ -282,7 +247,9 @@ __nss_hostname_digits_dots (const char *
172
if (inet_pton (AF_INET6, name, host_addr) <= 0)
174
*h_errnop = HOST_NOT_FOUND;
176
+ if (buffer_size == NULL)
177
+ *status = NSS_STATUS_NOTFOUND;
182
Index: b/nss/getXXbyYY_r.c
183
===================================================================
184
--- a/nss/getXXbyYY_r.c
185
+++ b/nss/getXXbyYY_r.c
186
@@ -178,6 +178,9 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, L
191
+ any_service = true;
196
Index: b/nss/test-digits-dots.c
197
===================================================================
199
+++ b/nss/test-digits-dots.c
201
+/* Copyright (C) 2013 Free Software Foundation, Inc.
202
+ This file is part of the GNU C Library.
204
+ The GNU C Library is free software; you can redistribute it and/or
205
+ modify it under the terms of the GNU Lesser General Public
206
+ License as published by the Free Software Foundation; either
207
+ version 2.1 of the License, or (at your option) any later version.
209
+ The GNU C Library is distributed in the hope that it will be useful,
210
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
211
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
212
+ Lesser General Public License for more details.
214
+ You should have received a copy of the GNU Lesser General Public
215
+ License along with the GNU C Library; if not, see
216
+ <http://www.gnu.org/licenses/>. */
218
+/* Testcase for BZ #15014 */
228
+ struct hostent *result = NULL;
229
+ struct hostent ret;
233
+ err = gethostbyname_r ("1.2.3.4", &ret, buf, sizeof (buf), &result, &h_err);
234
+ return err == ERANGE && h_err == NETDB_INTERNAL ? EXIT_SUCCESS : EXIT_FAILURE;
237
+#define TEST_FUNCTION do_test ()
238
+#include "../test-skeleton.c"
239
Index: b/nss/Makefile
240
===================================================================
243
@@ -46,7 +46,7 @@ routines-$(OPTION_EGLIBC_INET) += digits
245
install-bin := getent
247
-tests-$(OPTION_EGLIBC_INET) += test-netdb
248
+tests-$(OPTION_EGLIBC_INET) += test-netdb test-digits-dots
249
xtests-$(OPTION_EGLIBC_INET) += bug-erange
251
include ../Makeconfig