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