]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/glibc/glibc-rh1183534.patch
lcdproc: Update to 0.5.7
[ipfire-2.x.git] / src / patches / glibc / glibc-rh1183534.patch
1 commit d5dd6189d506068ed11c8bfa1e1e9bffde04decd
2 Author: Andreas Schwab <schwab@suse.de>
3 Date: Mon Jan 21 17:41:28 2013 +0100
4
5 Fix parsing of numeric hosts in gethostbyname_r
6
7 diff --git a/nss/Makefile b/nss/Makefile
8 index 449a258..553eafa 100644
9 --- a/nss/Makefile
10 +++ b/nss/Makefile
11 @@ -37,7 +37,7 @@ install-bin := getent makedb
12 others := getent
13 install-bin := getent
14
15 -tests = test-netdb tst-nss-test1
16 +tests = test-netdb tst-nss-test1 test-digits-dots
17 xtests = bug-erange
18
19 include ../Makeconfig
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,
25 {
26 if (h_errnop)
27 *h_errnop = NETDB_INTERNAL;
28 - *result = NULL;
29 + if (buffer_size == NULL)
30 + *status = NSS_STATUS_TRYAGAIN;
31 + else
32 + *result = NULL;
33 return -1;
34 }
35
36 @@ -83,14 +86,16 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
37 }
38
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);
43
44 if (buffer_size == NULL)
45 {
46 if (buflen < size_needed)
47 {
48 + *status = NSS_STATUS_TRYAGAIN;
49 if (h_errnop != NULL)
50 - *h_errnop = TRY_AGAIN;
51 + *h_errnop = NETDB_INTERNAL;
52 __set_errno (ERANGE);
53 goto done;
54 }
55 @@ -109,7 +114,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
56 *buffer_size = 0;
57 __set_errno (save);
58 if (h_errnop != NULL)
59 - *h_errnop = TRY_AGAIN;
60 + *h_errnop = NETDB_INTERNAL;
61 *result = NULL;
62 goto done;
63 }
64 @@ -149,7 +154,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
65 if (! ok)
66 {
67 *h_errnop = HOST_NOT_FOUND;
68 - if (buffer_size)
69 + if (buffer_size == NULL)
70 + *status = NSS_STATUS_NOTFOUND;
71 + else
72 *result = NULL;
73 goto done;
74 }
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;
78 else
79 - *result = resbuf;
80 + *result = resbuf;
81 goto done;
82 }
83
84 @@ -201,15 +208,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
85
86 if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
87 {
88 - const char *cp;
89 - char *hostname;
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;
94 - size_t size_needed;
95 - int addr_size;
96 -
97 switch (af)
98 {
99 default:
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;
104 - *result = NULL;
105 + if (buffer_size == NULL)
106 + *status = NSS_STATUS_NOTFOUND;
107 + else
108 + *result = NULL;
109 goto done;
110
111 case AF_INET6:
112 @@ -233,42 +234,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
113 break;
114 }
115
116 - size_needed = (sizeof (*host_addr)
117 - + sizeof (*h_addr_ptrs) + strlen (name) + 1);
118 -
119 - if (buffer_size == NULL && buflen < size_needed)
120 - {
121 - if (h_errnop != NULL)
122 - *h_errnop = TRY_AGAIN;
123 - __set_errno (ERANGE);
124 - goto done;
125 - }
126 - else if (buffer_size != NULL && *buffer_size < size_needed)
127 - {
128 - char *new_buf;
129 - *buffer_size = size_needed;
130 - new_buf = realloc (*buffer, *buffer_size);
131 -
132 - if (new_buf == NULL)
133 - {
134 - save = errno;
135 - free (*buffer);
136 - __set_errno (save);
137 - *buffer = NULL;
138 - *buffer_size = 0;
139 - *result = NULL;
140 - goto done;
141 - }
142 - *buffer = new_buf;
143 - }
144 -
145 - memset (*buffer, '\0', size_needed);
146 -
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);
151 -
152 for (cp = name;; ++cp)
153 {
154 if (!*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)
157 {
158 *h_errnop = HOST_NOT_FOUND;
159 - if (buffer_size)
160 + if (buffer_size == NULL)
161 + *status = NSS_STATUS_NOTFOUND;
162 + else
163 *result = NULL;
164 goto done;
165 }
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,
171 case -1:
172 return errno;
173 case 1:
174 +#ifdef NEED_H_ERRNO
175 + any_service = true;
176 +#endif
177 goto done;
178 }
179 #endif
180 diff --git a/nss/test-digits-dots.c b/nss/test-digits-dots.c
181 new file mode 100644
182 index 0000000..1efa344
183 --- /dev/null
184 +++ b/nss/test-digits-dots.c
185 @@ -0,0 +1,38 @@
186 +/* Copyright (C) 2013 Free Software Foundation, Inc.
187 + This file is part of the GNU C Library.
188 +
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.
193 +
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.
198 +
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/>. */
202 +
203 +/* Testcase for BZ #15014 */
204 +
205 +#include <stdlib.h>
206 +#include <netdb.h>
207 +#include <errno.h>
208 +
209 +static int
210 +do_test (void)
211 +{
212 + char buf[32];
213 + struct hostent *result = NULL;
214 + struct hostent ret;
215 + int h_err = 0;
216 + int err;
217 +
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;
220 +}
221 +
222 +#define TEST_FUNCTION do_test ()
223 +#include "../test-skeleton.c"