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

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