diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-05-04 15:01:11 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-05-04 15:01:11 +0000 |
commit | 33e337e34d69a2e298be8b6c109b601c2986339b (patch) | |
tree | df1037674f2c69011469485414315a50607f9d08 /libgo/go/encoding | |
parent | 1eae36f08cddc7779cd0ed75b359c9a54f67adff (diff) | |
download | gcc-33e337e34d69a2e298be8b6c109b601c2986339b.zip gcc-33e337e34d69a2e298be8b6c109b601c2986339b.tar.gz gcc-33e337e34d69a2e298be8b6c109b601c2986339b.tar.bz2 |
libgo: Update to Go 1.0.1 release.
From-SVN: r187163
Diffstat (limited to 'libgo/go/encoding')
-rw-r--r-- | libgo/go/encoding/ascii85/ascii85.go | 1 | ||||
-rw-r--r-- | libgo/go/encoding/ascii85/ascii85_test.go | 5 | ||||
-rw-r--r-- | libgo/go/encoding/asn1/asn1.go | 16 | ||||
-rw-r--r-- | libgo/go/encoding/asn1/asn1_test.go | 6 | ||||
-rw-r--r-- | libgo/go/encoding/base64/base64.go | 5 | ||||
-rw-r--r-- | libgo/go/encoding/base64/base64_test.go | 3 | ||||
-rw-r--r-- | libgo/go/encoding/json/encode.go | 9 | ||||
-rw-r--r-- | libgo/go/encoding/json/tagkey_test.go | 5 | ||||
-rw-r--r-- | libgo/go/encoding/pem/pem.go | 9 | ||||
-rw-r--r-- | libgo/go/encoding/pem/pem_test.go | 22 |
10 files changed, 58 insertions, 23 deletions
diff --git a/libgo/go/encoding/ascii85/ascii85.go b/libgo/go/encoding/ascii85/ascii85.go index 7d004b5..7050227 100644 --- a/libgo/go/encoding/ascii85/ascii85.go +++ b/libgo/go/encoding/ascii85/ascii85.go @@ -57,6 +57,7 @@ func Encode(dst, src []byte) int { if v == 0 && len(src) >= 4 { dst[0] = 'z' dst = dst[1:] + src = src[4:] n++ continue } diff --git a/libgo/go/encoding/ascii85/ascii85_test.go b/libgo/go/encoding/ascii85/ascii85_test.go index 70e67d8..42cf7e8 100644 --- a/libgo/go/encoding/ascii85/ascii85_test.go +++ b/libgo/go/encoding/ascii85/ascii85_test.go @@ -28,6 +28,11 @@ var pairs = []testpair{ "l(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G\n" + ">uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c\n", }, + // Special case when shortening !!!!! to z. + { + "\000\000\000\000", + "z", + }, } var bigtest = pairs[len(pairs)-1] diff --git a/libgo/go/encoding/asn1/asn1.go b/libgo/go/encoding/asn1/asn1.go index 3bf81a6..ac2b5f8 100644 --- a/libgo/go/encoding/asn1/asn1.go +++ b/libgo/go/encoding/asn1/asn1.go @@ -377,11 +377,6 @@ func parseTagAndLength(bytes []byte, initOffset int) (ret tagAndLength, offset i } else { // Bottom 7 bits give the number of length bytes to follow. numBytes := int(b & 0x7f) - // We risk overflowing a signed 32-bit number if we accept more than 3 bytes. - if numBytes > 3 { - err = StructuralError{"length too large"} - return - } if numBytes == 0 { err = SyntaxError{"indefinite length found (not DER)"} return @@ -394,8 +389,19 @@ func parseTagAndLength(bytes []byte, initOffset int) (ret tagAndLength, offset i } b = bytes[offset] offset++ + if ret.length >= 1<<23 { + // We can't shift ret.length up without + // overflowing. + err = StructuralError{"length too large"} + return + } ret.length <<= 8 ret.length |= int(b) + if ret.length == 0 { + // DER requires that lengths be minimal. + err = StructuralError{"superfluous leading zeros in length"} + return + } } } diff --git a/libgo/go/encoding/asn1/asn1_test.go b/libgo/go/encoding/asn1/asn1_test.go index 93803f4..eb848bd 100644 --- a/libgo/go/encoding/asn1/asn1_test.go +++ b/libgo/go/encoding/asn1/asn1_test.go @@ -283,6 +283,12 @@ var tagAndLengthData = []tagAndLengthTest{ {[]byte{0x00, 0x83, 0x01, 0x00}, false, tagAndLength{}}, {[]byte{0x1f, 0x85}, false, tagAndLength{}}, {[]byte{0x30, 0x80}, false, tagAndLength{}}, + // Superfluous zeros in the length should be an error. + {[]byte{0xa0, 0x82, 0x00, 0x01}, false, tagAndLength{}}, + // Lengths up to the maximum size of an int should work. + {[]byte{0xa0, 0x84, 0x7f, 0xff, 0xff, 0xff}, true, tagAndLength{2, 0, 0x7fffffff, true}}, + // Lengths that would overflow an int should be rejected. + {[]byte{0xa0, 0x84, 0x80, 0x00, 0x00, 0x00}, false, tagAndLength{}}, } func TestParseTagAndLength(t *testing.T) { diff --git a/libgo/go/encoding/base64/base64.go b/libgo/go/encoding/base64/base64.go index 55f9f67..f8a51a4e 100644 --- a/libgo/go/encoding/base64/base64.go +++ b/libgo/go/encoding/base64/base64.go @@ -230,7 +230,12 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) { if in == '=' && j >= 2 && len(src) < 4 { // We've reached the end and there's // padding + if len(src) == 0 && j == 2 { + // not enough padding + return n, false, CorruptInputError(len(osrc)) + } if len(src) > 0 && src[0] != '=' { + // incorrect padding return n, false, CorruptInputError(len(osrc) - len(src) - 1) } dlen = j diff --git a/libgo/go/encoding/base64/base64_test.go b/libgo/go/encoding/base64/base64_test.go index 3e9a843..9c35372 100644 --- a/libgo/go/encoding/base64/base64_test.go +++ b/libgo/go/encoding/base64/base64_test.go @@ -151,6 +151,9 @@ func TestDecodeCorrupt(t *testing.T) { {"AAA=AAAA", 3}, {"AAAAA", 4}, {"AAAAAA", 4}, + {"A=", 1}, + {"AA=", 3}, + {"AAAAAA=", 7}, } for _, e := range examples { diff --git a/libgo/go/encoding/json/encode.go b/libgo/go/encoding/json/encode.go index 14957b8..842672c 100644 --- a/libgo/go/encoding/json/encode.go +++ b/libgo/go/encoding/json/encode.go @@ -17,6 +17,7 @@ import ( "runtime" "sort" "strconv" + "strings" "sync" "unicode" "unicode/utf8" @@ -415,9 +416,11 @@ func isValidTag(s string) bool { return false } for _, c := range s { - switch c { - case '$', '-', '_', '/', '%': - // Acceptable + switch { + case strings.ContainsRune("!#$%&()*+-./:<=>?@[]^_{|}~", c): + // Backslash and quote chars are reserved, but + // otherwise any punctuation chars are allowed + // in a tag name. default: if !unicode.IsLetter(c) && !unicode.IsDigit(c) { return false diff --git a/libgo/go/encoding/json/tagkey_test.go b/libgo/go/encoding/json/tagkey_test.go index bba5730..da8b12b 100644 --- a/libgo/go/encoding/json/tagkey_test.go +++ b/libgo/go/encoding/json/tagkey_test.go @@ -40,6 +40,10 @@ type percentSlashTag struct { V string `json:"text/html%"` // http://golang.org/issue/2718 } +type punctuationTag struct { + V string `json:"!#$%&()*+-./:<=>?@[]^_{|}~"` // http://golang.org/issue/3546 +} + type emptyTag struct { W string } @@ -73,6 +77,7 @@ var structTagObjectKeyTests = []struct { {badFormatTag{"Orfevre"}, "Orfevre", "Y"}, {badCodeTag{"Reliable Man"}, "Reliable Man", "Z"}, {percentSlashTag{"brut"}, "brut", "text/html%"}, + {punctuationTag{"Union Rags"}, "Union Rags", "!#$%&()*+-./:<=>?@[]^_{|}~"}, } func TestStructTagObjectKey(t *testing.T) { diff --git a/libgo/go/encoding/pem/pem.go b/libgo/go/encoding/pem/pem.go index 38afbb4..3c1f5ab 100644 --- a/libgo/go/encoding/pem/pem.go +++ b/libgo/go/encoding/pem/pem.go @@ -28,9 +28,10 @@ type Block struct { } // getLine results the first \r\n or \n delineated line from the given byte -// array. The line does not include the \r\n or \n. The remainder of the byte -// array (also not including the new line bytes) is also returned and this will -// always be smaller than the original argument. +// array. The line does not include trailing whitespace or the trailing new +// line bytes. The remainder of the byte array (also not including the new line +// bytes) is also returned and this will always be smaller than the original +// argument. func getLine(data []byte) (line, rest []byte) { i := bytes.Index(data, []byte{'\n'}) var j int @@ -43,7 +44,7 @@ func getLine(data []byte) (line, rest []byte) { i-- } } - return data[0:i], data[j:] + return bytes.TrimRight(data[0:i], " \t"), data[j:] } // removeWhitespace returns a copy of its input with all spaces, tab and diff --git a/libgo/go/encoding/pem/pem_test.go b/libgo/go/encoding/pem/pem_test.go index 9ae1578..6133534 100644 --- a/libgo/go/encoding/pem/pem_test.go +++ b/libgo/go/encoding/pem/pem_test.go @@ -127,13 +127,13 @@ Certificate chain -----BEGIN CERTIFICATE----- testing -----BEGIN CERTIFICATE----- ------BEGIN CERTIFICATE----- +-----BEGIN CERTIFICATE----- MIID6TCCA1ICAQEwDQYJKoZIhvcNAQEFBQAwgYsxCzAJBgNVBAYTAlVTMRMwEQYD VQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMRQwEgYDVQQK -EwtHb29nbGUgSW5jLjEMMAoGA1UECxMDRW5nMQwwCgYDVQQDEwNhZ2wxHTAbBgkq -hkiG9w0BCQEWDmFnbEBnb29nbGUuY29tMB4XDTA5MDkwOTIyMDU0M1oXDTEwMDkw -OTIyMDU0M1owajELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAf -BgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEjMCEGA1UEAxMaZXVyb3Bh +EwtHb29nbGUgSW5jLjEMMAoGA1UECxMDRW5nMQwwCgYDVQQDEwNhZ2wxHTAbBgkq +hkiG9w0BCQEWDmFnbEBnb29nbGUuY29tMB4XDTA5MDkwOTIyMDU0M1oXDTEwMDkw +OTIyMDU0M1owajELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAf +BgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEjMCEGA1UEAxMaZXVyb3Bh LnNmby5jb3JwLmdvb2dsZS5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK AoICAQC6pgYt7/EibBDumASF+S0qvqdL/f+nouJw2T1Qc8GmXF/iiUcrsgzh/Fd8 pDhz/T96Qg9IyR4ztuc2MXrmPra+zAuSf5bevFReSqvpIt8Duv0HbDbcqs/XKPfB @@ -149,15 +149,15 @@ Pomjn71GNTtDeWAXibjCgdL6iHACCF6Htbl0zGlG0OAK+bdn0QIDAQABMA0GCSqG SIb3DQEBBQUAA4GBAOKnQDtqBV24vVqvesL5dnmyFpFPXBn3WdFfwD6DzEb21UVG 5krmJiu+ViipORJPGMkgoL6BjU21XI95VQbun5P8vvg8Z+FnFsvRFY3e1CCzAVQY ZsUkLw2I7zI/dNlWdB8Xp7v+3w9sX5N3J/WuJ1KOO5m26kRlHQo7EzT3974g ------END CERTIFICATE----- +-----END CERTIFICATE----- 1 s:/C=ZA/O=Ca Inc./CN=CA Inc ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,80C7C7A09690757A - +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,80C7C7A09690757A + eQp5ZkH6CyHBz7BZfUPxyLCCmftsBJ7HlqGb8Ld21cSwnzWZ4/SIlhyrUtsfw7VR -2TTwA+odo9ex7GdxOTaH8oZFumIRoiEjHsk8U7Bhntp+ekkPP79xunnN7hb7hkhr +2TTwA+odo9ex7GdxOTaH8oZFumIRoiEjHsk8U7Bhntp+ekkPP79xunnN7hb7hkhr yGDQZgA7s2cQHQ71v3gwT2BACAft26jCjbM1wgNzBnJ8M0Rzn68YWqaPtdBu8qb/ zVR5JB1mnqvTSbFsfF5yMc6o2WQ9jJCl6KypnMl+BpL+dlvdjYVK4l9lYsB1Hs3d +zDBbWxos818zzhS8/y6eIfiSG27cqrbhURbmgiSfDXjncK4m/pLcQ7mmBL6mFOr |