Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix resolver inet_* namespace (bug 17722).
Parts of the resolver brought in by pthreads (at least) use inet_*
functions that aren't in the 1995/6 edition of POSIX that introduced
pthreads (or in one case, use __inet_aton which is then defined in the
same file as non-weak inet_addr).  This patch fixes this by making the
affected functions into weak alias for __inet_* and using those names
in the problematic resolver code.

Tested for x86_64 (testsuite, and that disassembly of installed shared
libraries is unchanged by the patch).

	[BZ #17722]
	* inet/inet_mkadr.c (inet_makeaddr): Rename to __inet_makeaddr and
	define as weak alias of __inet_makeaddr.
	* resolv/inet_addr.c (inet_addr): Rename to __inet_addr and define
	as weak alias of __inet_addr.
	* resolv/inet_pton.c (inet_pton): Rename to __inet_pton and define
	as weak alias of __inet_pton.  Use libc_hidden_weak.
	* include/arpa/inet.h (__inet_pton): Declare.  Use
	libc_hidden_proto.
	(inet_makeaddr): Don't use libc_hidden_proto.
	(__inet_makeaddr): Declare.  Use libc_hidden_proto.
	* resolv/res_init.c (__res_vinit): Use __inet_pton instead of
	inet_pton.  Use __inet_makeaddr instead of inet_makeaddr.
	* conform/Makefile (test-xfail-POSIX/pthread.h/linknamespace):
	Remove variable.
	(test-xfail-POSIX/sched.h/linknamespace): Likewise.
	(test-xfail-POSIX/time.h/linknamespace): Likewise.
  • Loading branch information
Joseph Myers committed Dec 17, 2014
1 parent 66ce3cb commit 8ac5a76
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
20 changes: 20 additions & 0 deletions ChangeLog
@@ -1,3 +1,23 @@
2014-12-17 Joseph Myers <joseph@codesourcery.com>

[BZ #17722]
* inet/inet_mkadr.c (inet_makeaddr): Rename to __inet_makeaddr and
define as weak alias of __inet_makeaddr.
* resolv/inet_addr.c (inet_addr): Rename to __inet_addr and define
as weak alias of __inet_addr.
* resolv/inet_pton.c (inet_pton): Rename to __inet_pton and define
as weak alias of __inet_pton. Use libc_hidden_weak.
* include/arpa/inet.h (__inet_pton): Declare. Use
libc_hidden_proto.
(inet_makeaddr): Don't use libc_hidden_proto.
(__inet_makeaddr): Declare. Use libc_hidden_proto.
* resolv/res_init.c (__res_vinit): Use __inet_pton instead of
inet_pton. Use __inet_makeaddr instead of inet_makeaddr.
* conform/Makefile (test-xfail-POSIX/pthread.h/linknamespace):
Remove variable.
(test-xfail-POSIX/sched.h/linknamespace): Likewise.
(test-xfail-POSIX/time.h/linknamespace): Likewise.

2014-12-17 Steve Ellcey <sellcey@imgtec.com>

* inet/getnetgrent_r.c: Move while loop to be inside if statement.
Expand Down
3 changes: 2 additions & 1 deletion NEWS
Expand Up @@ -14,7 +14,8 @@ Version 2.21
17363, 17370, 17371, 17411, 17460, 17475, 17485, 17501, 17506, 17508,
17522, 17555, 17570, 17571, 17572, 17573, 17574, 17581, 17582, 17583,
17584, 17585, 17589, 17594, 17601, 17608, 17616, 17625, 17630, 17633,
17634, 17647, 17653, 17657, 17664, 17665, 17668, 17682, 17717, 17719.
17634, 17647, 17653, 17657, 17664, 17665, 17668, 17682, 17717, 17719,
17722.

* CVE-2104-7817 The wordexp function could ignore the WRDE_NOCMD flag
under certain input conditions resulting in the execution of a shell for
Expand Down
3 changes: 0 additions & 3 deletions conform/Makefile
Expand Up @@ -371,11 +371,8 @@ test-xfail-POSIX/aio.h/linknamespace = yes
test-xfail-POSIX/fnmatch.h/linknamespace = yes
test-xfail-POSIX/glob.h/linknamespace = yes
test-xfail-POSIX/mqueue.h/linknamespace = yes
test-xfail-POSIX/pthread.h/linknamespace = yes
test-xfail-POSIX/regex.h/linknamespace = yes
test-xfail-POSIX/sched.h/linknamespace = yes
test-xfail-POSIX/semaphore.h/linknamespace = yes
test-xfail-POSIX/time.h/linknamespace = yes
test-xfail-POSIX/unistd.h/linknamespace = yes
test-xfail-POSIX/wordexp.h/linknamespace = yes
test-xfail-UNIX98/ctype.h/linknamespace = yes
Expand Down
5 changes: 4 additions & 1 deletion include/arpa/inet.h
Expand Up @@ -7,6 +7,9 @@ libc_hidden_proto (__inet_aton)
libc_hidden_proto (inet_aton)
libc_hidden_proto (inet_ntop)
libc_hidden_proto (inet_pton)
libc_hidden_proto (inet_makeaddr)
extern __typeof (inet_pton) __inet_pton;
libc_hidden_proto (__inet_pton)
extern __typeof (inet_makeaddr) __inet_makeaddr;
libc_hidden_proto (__inet_makeaddr)
libc_hidden_proto (inet_netof)
#endif
5 changes: 3 additions & 2 deletions inet/inet_mkadr.c
Expand Up @@ -40,7 +40,7 @@ static char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93";
* building addresses stored in the ifnet structure.
*/
struct in_addr
inet_makeaddr(net, host)
__inet_makeaddr(net, host)
in_addr_t net, host;
{
struct in_addr in;
Expand All @@ -56,4 +56,5 @@ inet_makeaddr(net, host)
in.s_addr = htonl(in.s_addr);
return in;
}
libc_hidden_def (inet_makeaddr)
libc_hidden_def (__inet_makeaddr)
weak_alias (__inet_makeaddr, inet_makeaddr)
3 changes: 2 additions & 1 deletion resolv/inet_addr.c
Expand Up @@ -90,13 +90,14 @@ static const char rcsid[] = "$BINDId: inet_addr.c,v 8.11 1999/10/13 16:39:25 vix
* The value returned is in network order.
*/
in_addr_t
inet_addr(const char *cp) {
__inet_addr(const char *cp) {
struct in_addr val;

if (__inet_aton(cp, &val))
return (val.s_addr);
return (INADDR_NONE);
}
weak_alias (__inet_addr, inet_addr)

/*
* Check whether "cp" is a valid ascii representation
Expand Down
6 changes: 4 additions & 2 deletions resolv/inet_pton.c
Expand Up @@ -49,7 +49,7 @@ static int inet_pton6 (const char *src, u_char *dst) internal_function;
* Paul Vixie, 1996.
*/
int
inet_pton(af, src, dst)
__inet_pton(af, src, dst)
int af;
const char *src;
void *dst;
Expand All @@ -65,7 +65,9 @@ inet_pton(af, src, dst)
}
/* NOTREACHED */
}
libc_hidden_def (inet_pton)
libc_hidden_def (__inet_pton)
weak_alias (__inet_pton, inet_pton)
libc_hidden_weak (inet_pton)

/* int
* inet_pton4(src, dst)
Expand Down
4 changes: 2 additions & 2 deletions resolv/res_init.c
Expand Up @@ -324,7 +324,7 @@ __res_vinit(res_state statp, int preinit) {
if ((el = strchr(cp, SCOPE_DELIMITER)) != NULL)
*el = '\0';
if ((*cp != '\0') &&
(inet_pton(AF_INET6, cp, &a6) > 0)) {
(__inet_pton(AF_INET6, cp, &a6) > 0)) {
struct sockaddr_in6 *sa6;

sa6 = malloc(sizeof(*sa6));
Expand Down Expand Up @@ -428,7 +428,7 @@ __res_vinit(res_state statp, int preinit) {
(void) fclose(fp);
}
if (__builtin_expect(statp->nscount == 0, 0)) {
statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
statp->nsaddr.sin_addr = __inet_makeaddr(IN_LOOPBACKNET, 1);
statp->nsaddr.sin_family = AF_INET;
statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
statp->nscount = 1;
Expand Down

0 comments on commit 8ac5a76

Please sign in to comment.