Module Name:    src
Committed By:   christos
Date:           Thu Dec 28 15:12:16 UTC 2017

Modified Files:
        src/lib/libc/net: getaddrinfo.c

Log Message:
PR/52837: Michael Kaufmann: getaddrinfo() resolves "127.0.0.1 www.example.com"
to 127.0.0.1. Apply the patch from FreeBSD and explain the rationale.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/lib/libc/net/getaddrinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.116 src/lib/libc/net/getaddrinfo.c:1.117
--- src/lib/libc/net/getaddrinfo.c:1.116	Thu Sep 28 20:04:33 2017
+++ src/lib/libc/net/getaddrinfo.c	Thu Dec 28 10:12:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.116 2017/09/29 00:04:33 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.117 2017/12/28 15:12:15 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.116 2017/09/29 00:04:33 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.117 2017/12/28 15:12:15 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -1322,8 +1322,15 @@ explore_numeric(const struct addrinfo *p
 		* check for errors. inet_pton() only accepts addresses
 		* in the dotted quad format and only in base 10, so we
 		* need to treat AF_INET specially.
+		*
+		* We also check for trailing characters and fail if there
+		* are any. This matches the inet_pton6(), but not the
+		* inet_pton4() behavior. We choose to make the protocol
+		* behavior consistent.
 		*/
-		if (inet_aton(hostname, (void *)pton) == 1) {
+		if (inet_aton(hostname, (void *)pton) == 1 &&
+		    hostname[strspn(hostname, "0123456789.xabcdefXABCDEF")]
+		    == '\0') {
 			if (pai->ai_family == afd->a_af ||
 			    pai->ai_family == PF_UNSPEC /*?*/) {
 				GET_AI(cur->ai_next, afd, pton);

Reply via email to