about summary refs log tree commit diff
path: root/sysdeps/posix
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 /sysdeps/posix
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 'sysdeps/posix')
-rw-r--r--sysdeps/posix/getaddrinfo.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 09fbc83cf8..740e9555d5 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -82,6 +82,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <nscd/nscd_proto.h>
 #include <resolv/res_hconf.h>
 #include <scratch_buffer.h>
+#include <inet/net-internal.h>
 
 #ifdef HAVE_LIBIDN
 extern int __idna_to_ascii_lz (const char *input, char **output, int flags);
@@ -570,31 +571,13 @@ gaih_inet (const char *name, const struct gaih_service *service,
 		  goto free_and_return;
 		}
 
-	      if (scope_delim != NULL)
+	      if (scope_delim != NULL
+		  && __inet6_scopeid_pton ((struct in6_addr *) at->addr,
+					   scope_delim + 1,
+					   &at->scopeid) != 0)
 		{
-		  int try_numericscope = 0;
-		  if (IN6_IS_ADDR_LINKLOCAL (at->addr)
-		      || IN6_IS_ADDR_MC_LINKLOCAL (at->addr))
-		    {
-		      at->scopeid = if_nametoindex (scope_delim + 1);
-		      if (at->scopeid == 0)
-			try_numericscope = 1;
-		    }
-		  else
-		    try_numericscope = 1;
-
-		  if (try_numericscope != 0)
-		    {
-		      char *end;
-		      assert (sizeof (uint32_t) <= sizeof (unsigned long));
-		      at->scopeid = (uint32_t) strtoul (scope_delim + 1, &end,
-							10);
-		      if (*end != '\0')
-			{
-			  result = -EAI_NONAME;
-			  goto free_and_return;
-			}
-		    }
+		  result = -EAI_NONAME;
+		  goto free_and_return;
 		}
 
 	      if (req->ai_flags & AI_CANONNAME)