Blame SOURCES/reject-leading-zeros.patch

c78fef
diff --git a/doc/go1.16.html b/doc/go1.16.html
c78fef
index 0beb62d..fc6b668 100644
c78fef
--- a/doc/go1.16.html
c78fef
+++ b/doc/go1.16.html
c78fef
@@ -891,6 +891,14 @@ func TestFoo(t *testing.T) {
c78fef
       is missing; this is common on musl-based systems and makes
c78fef
       Go programs match the behavior of C programs on those systems.
c78fef
     

c78fef
+    

c78fef
+      The ParseIP and ParseCIDR
c78fef
+      functions now reject IPv4 addresses which contain decimal components with leading zeros.
c78fef
+      These components were always interpreted as decimal, but some operating systems treat them as octal.
c78fef
+      This mismatch could hypothetically lead to security issues if a Go application was used to validate IP addresses
c78fef
+      which were then used in their original form with non-Go applications which interpreted components as octal. Generally,
c78fef
+      it is advisable to always re-encoded values after validation, which avoids this class of parser misalignment issues.
c78fef
+    

c78fef
   
c78fef
 
c78fef
 
c78fef
diff --git a/src/net/hosts_test.go b/src/net/hosts_test.go
c78fef
index f850e2f..19c4399 100644
c78fef
--- a/src/net/hosts_test.go
c78fef
+++ b/src/net/hosts_test.go
c78fef
@@ -36,7 +36,7 @@ var lookupStaticHostTests = []struct {
c78fef
 		},
c78fef
 	},
c78fef
 	{
c78fef
-		"testdata/ipv4-hosts", // see golang.org/issue/8996
c78fef
+		"testdata/ipv4-hosts",
c78fef
 		[]staticHostEntry{
c78fef
 			{"localhost", []string{"127.0.0.1", "127.0.0.2", "127.0.0.3"}},
c78fef
 			{"localhost.localdomain", []string{"127.0.0.3"}},
c78fef
@@ -102,7 +102,7 @@ var lookupStaticAddrTests = []struct {
c78fef
 		},
c78fef
 	},
c78fef
 	{
c78fef
-		"testdata/ipv4-hosts", // see golang.org/issue/8996
c78fef
+		"testdata/ipv4-hosts",
c78fef
 		[]staticHostEntry{
c78fef
 			{"127.0.0.1", []string{"localhost"}},
c78fef
 			{"127.0.0.2", []string{"localhost"}},
c78fef
diff --git a/src/net/ip.go b/src/net/ip.go
c78fef
index c00fe8e..007f3f7 100644
c78fef
--- a/src/net/ip.go
c78fef
+++ b/src/net/ip.go
c78fef
@@ -552,6 +552,10 @@ func parseIPv4(s string) IP {
c78fef
 		if !ok || n > 0xFF {
c78fef
 			return nil
c78fef
 		}
c78fef
+		if c > 1 && s[0] == '0' {
c78fef
+			// Reject non-zero components with leading zeroes.
c78fef
+			return nil
c78fef
+		}
c78fef
 		s = s[c:]
c78fef
 		p[i] = byte(n)
c78fef
 	}
c78fef
diff --git a/src/net/ip_test.go b/src/net/ip_test.go
c78fef
index a5fc5e6..585381d 100644
c78fef
--- a/src/net/ip_test.go
c78fef
+++ b/src/net/ip_test.go
c78fef
@@ -20,9 +20,7 @@ var parseIPTests = []struct {
c78fef
 }{
c78fef
 	{"127.0.1.2", IPv4(127, 0, 1, 2)},
c78fef
 	{"127.0.0.1", IPv4(127, 0, 0, 1)},
c78fef
-	{"127.001.002.003", IPv4(127, 1, 2, 3)},
c78fef
 	{"::ffff:127.1.2.3", IPv4(127, 1, 2, 3)},
c78fef
-	{"::ffff:127.001.002.003", IPv4(127, 1, 2, 3)},
c78fef
 	{"::ffff:7f01:0203", IPv4(127, 1, 2, 3)},
c78fef
 	{"0:0:0:0:0000:ffff:127.1.2.3", IPv4(127, 1, 2, 3)},
c78fef
 	{"0:0:0:0:000000:ffff:127.1.2.3", IPv4(127, 1, 2, 3)},
c78fef
@@ -42,6 +40,11 @@ var parseIPTests = []struct {
c78fef
 	{"fe80::1%911", nil},
c78fef
 	{"", nil},
c78fef
 	{"a1:a2:a3:a4::b1:b2:b3:b4", nil}, // Issue 6628
c78fef
+	{"127.001.002.003", nil},
c78fef
+	{"::ffff:127.001.002.003", nil},
c78fef
+	{"123.000.000.000", nil},
c78fef
+	{"1.2..4", nil},
c78fef
+	{"0123.0.0.1", nil},
c78fef
 }
c78fef
 
c78fef
 func TestParseIP(t *testing.T) {
c78fef
@@ -357,6 +360,7 @@ var parseCIDRTests = []struct {
c78fef
 	{"0.0.-2.0/32", nil, nil, &ParseError{Type: "CIDR address", Text: "0.0.-2.0/32"}},
c78fef
 	{"0.0.0.-3/32", nil, nil, &ParseError{Type: "CIDR address", Text: "0.0.0.-3/32"}},
c78fef
 	{"0.0.0.0/-0", nil, nil, &ParseError{Type: "CIDR address", Text: "0.0.0.0/-0"}},
c78fef
+	{"127.000.000.001/32", nil, nil, &ParseError{Type: "CIDR address", Text: "127.000.000.001/32"}},
c78fef
 	{"", nil, nil, &ParseError{Type: "CIDR address", Text: ""}},
c78fef
 }
c78fef
 
c78fef
diff --git a/src/net/testdata/ipv4-hosts b/src/net/testdata/ipv4-hosts
c78fef
index 5208bb4..6b99675 100644
c78fef
--- a/src/net/testdata/ipv4-hosts
c78fef
+++ b/src/net/testdata/ipv4-hosts
c78fef
@@ -1,12 +1,8 @@
c78fef
 # See https://tools.ietf.org/html/rfc1123.
c78fef
-#
c78fef
-# The literal IPv4 address parser in the net package is a relaxed
c78fef
-# one. It may accept a literal IPv4 address in dotted-decimal notation
c78fef
-# with leading zeros such as "001.2.003.4".
c78fef
 
c78fef
 # internet address and host name
c78fef
 127.0.0.1	localhost	# inline comment separated by tab
c78fef
-127.000.000.002	localhost       # inline comment separated by space
c78fef
+127.0.0.2	localhost   # inline comment separated by space
c78fef
 
c78fef
 # internet address, host name and aliases
c78fef
-127.000.000.003	localhost	localhost.localdomain
c78fef
+127.0.0.3	localhost	localhost.localdomain