about summary refs log tree commit diff
path: root/resolv/res_init.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-09-15 15:46:30 +0200
committerFlorian Weimer <fweimer@redhat.com>2016-09-15 15:46:30 +0200
commit80d8cb91dee8bdcc4e430b3e2620d95f89b1ee0b (patch)
tree3a0f59d773e165332cc67d89f2e8ef181d5b49fd /resolv/res_init.c
parenta0a9b6e376b75c07b4f65f270f008ce035bbf536 (diff)
downloadglibc-80d8cb91dee8bdcc4e430b3e2620d95f89b1ee0b.tar.gz
glibc-80d8cb91dee8bdcc4e430b3e2620d95f89b1ee0b.tar.xz
glibc-80d8cb91dee8bdcc4e430b3e2620d95f89b1ee0b.zip
inet: Add __inet6_scopeid_pton function [BZ #20611]
__inet6_scopeid_pton implements strict validation of numeric scope IDs.
Use it in getaddrinfo and __res_vinit.
Diffstat (limited to 'resolv/res_init.c')
-rw-r--r--resolv/res_init.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/resolv/res_init.c b/resolv/res_init.c
index cfb8188ca1..bfae537da4 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -81,6 +81,7 @@
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <inet/net-internal.h>
 
 #include <not-cancel.h>
 
@@ -283,26 +284,12 @@ __res_vinit(res_state statp, int preinit) {
 				sa6->sin6_flowinfo = 0;
 				sa6->sin6_addr = a6;
 
-				if (__glibc_likely (el == NULL))
-				    sa6->sin6_scope_id = 0;
-				else {
-				    int try_numericscope = 1;
-				    if (IN6_IS_ADDR_LINKLOCAL (&a6)
-					|| IN6_IS_ADDR_MC_LINKLOCAL (&a6)) {
-					sa6->sin6_scope_id
-					  = __if_nametoindex (el + 1);
-					if (sa6->sin6_scope_id != 0)
-					    try_numericscope = 0;
-				    }
-
-				    if (try_numericscope) {
-					char *end;
-					sa6->sin6_scope_id
-					  = (uint32_t) strtoul (el + 1, &end,
-								10);
-					if (*end != '\0')
-					    sa6->sin6_scope_id = 0;
-				    }
+				sa6->sin6_scope_id = 0;
+				if (__glibc_likely (el != NULL)) {
+				  /* Ignore errors, for backwards
+				     compatibility.  */
+				  (void) __inet6_scopeid_pton
+				    (&a6, el + 1, &sa6->sin6_scope_id);
 				}
 
 				statp->nsaddr_list[nserv].sin_family = 0;