]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/glibc/glibc-rh1183533.patch
core97: remove some core98 files from update filelist.
[ipfire-2.x.git] / src / patches / glibc / glibc-rh1183533.patch
CommitLineData
fe875de8
MT
1commit d5dd6189d506068ed11c8bfa1e1e9bffde04decd
2Author: Andreas Schwab <schwab@suse.de>
3Date: Mon Jan 21 17:41:28 2013 +0100
4
5 Fix parsing of numeric hosts in gethostbyname_r
6
7diff --git a/nss/digits_dots.c b/nss/digits_dots.c
8index 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,
12 {
13 if (h_errnop)
14 *h_errnop = NETDB_INTERNAL;
15- *result = NULL;
16+ if (buffer_size == NULL)
17+ *status = NSS_STATUS_TRYAGAIN;
18+ else
19+ *result = NULL;
20 return -1;
21 }
22
23@@ -83,14 +86,16 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
24 }
25
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);
30
31 if (buffer_size == NULL)
32 {
33 if (buflen < size_needed)
34 {
35+ *status = NSS_STATUS_TRYAGAIN;
36 if (h_errnop != NULL)
37- *h_errnop = TRY_AGAIN;
38+ *h_errnop = NETDB_INTERNAL;
39 __set_errno (ERANGE);
40 goto done;
41 }
42@@ -109,7 +114,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
43 *buffer_size = 0;
44 __set_errno (save);
45 if (h_errnop != NULL)
46- *h_errnop = TRY_AGAIN;
47+ *h_errnop = NETDB_INTERNAL;
48 *result = NULL;
49 goto done;
50 }
51@@ -149,7 +154,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
52 if (! ok)
53 {
54 *h_errnop = HOST_NOT_FOUND;
55- if (buffer_size)
56+ if (buffer_size == NULL)
57+ *status = NSS_STATUS_NOTFOUND;
58+ else
59 *result = NULL;
60 goto done;
61 }
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;
65 else
66- *result = resbuf;
67+ *result = resbuf;
68 goto done;
69 }
70
71@@ -201,15 +208,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
72
73 if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
74 {
75- const char *cp;
76- char *hostname;
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;
81- size_t size_needed;
82- int addr_size;
83-
84 switch (af)
85 {
86 default:
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;
91- *result = NULL;
92+ if (buffer_size == NULL)
93+ *status = NSS_STATUS_NOTFOUND;
94+ else
95+ *result = NULL;
96 goto done;
97
98 case AF_INET6:
99@@ -233,42 +234,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
100 break;
101 }
102
103- size_needed = (sizeof (*host_addr)
104- + sizeof (*h_addr_ptrs) + strlen (name) + 1);
105-
106- if (buffer_size == NULL && buflen < size_needed)
107- {
108- if (h_errnop != NULL)
109- *h_errnop = TRY_AGAIN;
110- __set_errno (ERANGE);
111- goto done;
112- }
113- else if (buffer_size != NULL && *buffer_size < size_needed)
114- {
115- char *new_buf;
116- *buffer_size = size_needed;
117- new_buf = realloc (*buffer, *buffer_size);
118-
119- if (new_buf == NULL)
120- {
121- save = errno;
122- free (*buffer);
123- __set_errno (save);
124- *buffer = NULL;
125- *buffer_size = 0;
126- *result = NULL;
127- goto done;
128- }
129- *buffer = new_buf;
130- }
131-
132- memset (*buffer, '\0', size_needed);
133-
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);
138-
139 for (cp = name;; ++cp)
140 {
141 if (!*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)
144 {
145 *h_errnop = HOST_NOT_FOUND;
146- if (buffer_size)
147+ if (buffer_size == NULL)
148+ *status = NSS_STATUS_NOTFOUND;
149+ else
150 *result = NULL;
151 goto done;
152 }
153diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
154index 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,
158 case -1:
159 return errno;
160 case 1:
161+#ifdef NEED_H_ERRNO
162+ any_service = true;
163+#endif
164 goto done;
165 }
166 #endif
167diff --git a/nss/test-digits-dots.c b/nss/test-digits-dots.c
168new file mode 100644
169index 0000000..1efa344
170--- /dev/null
171+++ b/nss/test-digits-dots.c
172@@ -0,0 +1,38 @@
173+/* Copyright (C) 2013 Free Software Foundation, Inc.
174+ This file is part of the GNU C Library.
175+
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.
180+
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.
185+
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/>. */
189+
190+/* Testcase for BZ #15014 */
191+
192+#include <stdlib.h>
193+#include <netdb.h>
194+#include <errno.h>
195+
196+static int
197+do_test (void)
198+{
199+ char buf[32];
200+ struct hostent *result = NULL;
201+ struct hostent ret;
202+ int h_err = 0;
203+ int err;
204+
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;
207+}
208+
209+#define TEST_FUNCTION do_test ()
210+#include "../test-skeleton.c"