From 80d8cb91dee8bdcc4e430b3e2620d95f89b1ee0b Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 15 Sep 2016 15:46:30 +0200 Subject: 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. --- sysdeps/posix/getaddrinfo.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'sysdeps/posix') 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 #include #include +#include #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) -- cgit 1.4.1