arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh677316-inet_pton-zeros.patch

147e83
Revert this upstream commit:
147e83
147e83
commit 9a0cc8c1bd7645bf3c988890ffb59639c07a5812
147e83
Author: Florian Weimer <fweimer@redhat.com>
147e83
Date:   Fri Jun 23 22:51:00 2017 +0200
147e83
147e83
    inet_pton: Reject IPv6 addresses with many leading zeros [BZ #16637]
147e83
    
147e83
    2001:db8:00001::f is not a valid IPv6 address according to RFC 2373.
147e83
147e83
We do not want this behavioral change in Red Hat Enterprise Linux 7.
147e83
See rhbz#1484034 for some discussion.
147e83
147e83
diff --git a/resolv/inet_pton.c b/resolv/inet_pton.c
147e83
index 16ee33e0c0dfb015..b95da47c17ef8afc 100644
147e83
--- a/resolv/inet_pton.c
147e83
+++ b/resolv/inet_pton.c
147e83
@@ -144,8 +144,7 @@ inet_pton6 (const char *src, const char *src_endp, unsigned char *dst)
147e83
 {
147e83
   unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
147e83
   const char *curtok;
147e83
-  int ch;
147e83
-  size_t xdigits_seen;	/* Number of hex digits since colon.  */
147e83
+  int ch, saw_xdigit;
147e83
   unsigned int val;
147e83
 
147e83
   tp = memset (tmp, '\0', NS_IN6ADDRSZ);
147e83
@@ -163,7 +162,7 @@ inet_pton6 (const char *src, const char *src_endp, unsigned char *dst)
147e83
     }
147e83
 
147e83
   curtok = src;
147e83
-  xdigits_seen = 0;
147e83
+  saw_xdigit = 0;
147e83
   val = 0;
147e83
   while (src < src_endp)
147e83
     {
147e83
@@ -171,19 +170,17 @@ inet_pton6 (const char *src, const char *src_endp, unsigned char *dst)
147e83
       int digit = hex_digit_value (ch);
147e83
       if (digit >= 0)
147e83
 	{
147e83
-	  if (xdigits_seen == 4)
147e83
-	    return 0;
147e83
 	  val <<= 4;
147e83
 	  val |= digit;
147e83
 	  if (val > 0xffff)
147e83
 	    return 0;
147e83
-	  ++xdigits_seen;
147e83
+	  saw_xdigit = 1;
147e83
 	  continue;
147e83
 	}
147e83
       if (ch == ':')
147e83
 	{
147e83
 	  curtok = src;
147e83
-	  if (xdigits_seen == 0)
147e83
+	  if (!saw_xdigit)
147e83
 	    {
147e83
 	      if (colonp)
147e83
 		return 0;
147e83
@@ -196,7 +193,7 @@ inet_pton6 (const char *src, const char *src_endp, unsigned char *dst)
147e83
 	    return 0;
147e83
 	  *tp++ = (unsigned char) (val >> 8) & 0xff;
147e83
 	  *tp++ = (unsigned char) val & 0xff;
147e83
-	  xdigits_seen = 0;
147e83
+	  saw_xdigit = 0;
147e83
 	  val = 0;
147e83
 	  continue;
147e83
 	}
147e83
@@ -204,12 +201,12 @@ inet_pton6 (const char *src, const char *src_endp, unsigned char *dst)
147e83
           && inet_pton4 (curtok, src_endp, tp) > 0)
147e83
 	{
147e83
 	  tp += NS_INADDRSZ;
147e83
-	  xdigits_seen = 0;
147e83
+	  saw_xdigit = 0;
147e83
 	  break;  /* '\0' was seen by inet_pton4.  */
147e83
 	}
147e83
       return 0;
147e83
     }
147e83
-  if (xdigits_seen > 0)
147e83
+  if (saw_xdigit)
147e83
     {
147e83
       if (tp + NS_INT16SZ > endp)
147e83
 	return 0;
147e83
diff --git a/resolv/tst-inet_pton.c b/resolv/tst-inet_pton.c
147e83
index 4bb9f8119378b467..7fffb24cdf9eb1f4 100644
147e83
--- a/resolv/tst-inet_pton.c
147e83
+++ b/resolv/tst-inet_pton.c
147e83
@@ -226,7 +226,13 @@ const struct test_case test_cases[] =
147e83
     },
147e83
     {.input = "2", },
147e83
     {.input = "2.", },
147e83
-    {.input = "2001:db8:00001::f", },
147e83
+    {.input = "2001:db8:00001::f",
147e83
+     .ipv6_ok = true,
147e83
+     .ipv6_expected = {
147e83
+       0x20, 0x1, 0xd, 0xb8, 0x0, 0x1, 0x0, 0x0,
147e83
+       0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf
147e83
+     },
147e83
+    },
147e83
     {.input = "2001:db8:10000::f", },
147e83
     {.input = "2001:db8:1234:5678:abcd:ef01:2345:67",
147e83
      .ipv6_ok = true,
147e83
@@ -448,7 +454,13 @@ const struct test_case test_cases[] =
147e83
        0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
147e83
      },
147e83
     },
147e83
-    {.input = "::00001", },
147e83
+    {.input = "::00001",
147e83
+     .ipv6_ok = true,
147e83
+     .ipv6_expected = {
147e83
+       0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
147e83
+       0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1
147e83
+     },
147e83
+    },
147e83
     {.input = "::1",
147e83
      .ipv6_ok = true,
147e83
      .ipv6_expected = {