Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net PR/52837: Michael Kaufmann: getaddrinfo() resol...



details:   https://anonhg.NetBSD.org/src/rev/93ac49638f90
branches:  trunk
changeset: 828718:93ac49638f90
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Dec 28 15:12:15 2017 +0000

description:
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.

diffstat:

 lib/libc/net/getaddrinfo.c |  13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diffs (35 lines):

diff -r bc7c459b06a6 -r 93ac49638f90 lib/libc/net/getaddrinfo.c
--- a/lib/libc/net/getaddrinfo.c        Thu Dec 28 14:34:39 2017 +0000
+++ b/lib/libc/net/getaddrinfo.c        Thu Dec 28 15:12:15 2017 +0000
@@ -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 @@
                * 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);



Home | Main Index | Thread Index | Old Index