diff options
author | Dmitri Shuralyov <dmitshur@google.com> | 2022-04-13 15:33:25 +0000 |
---|---|---|
committer | Dmitri Shuralyov <dmitshur@google.com> | 2022-04-13 15:33:25 +0000 |
commit | ed86dfc4e441ee7597586dd858fb87c987f1f3c8 (patch) | |
tree | 5a8bc12cf9f7ca932a82e4f8564b18ed928a93e9 /src/encoding/pem/pem_test.go | |
parent | 4ea866a9969f4ff2ffd975116a17bbe01ce00469 (diff) | |
parent | 346b18ee9d15410ab08dd583787c64dbed0666d2 (diff) | |
download | go-ed86dfc4e441ee7597586dd858fb87c987f1f3c8.tar.gz go-ed86dfc4e441ee7597586dd858fb87c987f1f3c8.zip |
[dev.boringcrypto.go1.17] all: merge go1.17.9 into dev.boringcrypto.go1.17
Change-Id: I65c66a480c706b9bf453e7df68afdb7fc163f58b
Diffstat (limited to 'src/encoding/pem/pem_test.go')
-rw-r--r-- | src/encoding/pem/pem_test.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/encoding/pem/pem_test.go b/src/encoding/pem/pem_test.go index b2b6b15e73..c94b5ca53b 100644 --- a/src/encoding/pem/pem_test.go +++ b/src/encoding/pem/pem_test.go @@ -107,6 +107,12 @@ const pemMissingEndingSpace = ` dGVzdA== -----ENDBAR-----` +const pemMissingEndLine = ` +-----BEGIN FOO----- +Header: 1` + +var pemRepeatingBegin = strings.Repeat("-----BEGIN \n", 10) + var badPEMTests = []struct { name string input string @@ -131,14 +137,34 @@ var badPEMTests = []struct { "missing ending space", pemMissingEndingSpace, }, + { + "repeating begin", + pemRepeatingBegin, + }, + { + "missing end line", + pemMissingEndLine, + }, } func TestBadDecode(t *testing.T) { for _, test := range badPEMTests { - result, _ := Decode([]byte(test.input)) + result, rest := Decode([]byte(test.input)) if result != nil { t.Errorf("unexpected success while parsing %q", test.name) } + if string(rest) != test.input { + t.Errorf("unexpected rest: %q; want = %q", rest, test.input) + } + } +} + +func TestCVE202224675(t *testing.T) { + // Prior to CVE-2022-24675, this input would cause a stack overflow. + input := []byte(strings.Repeat("-----BEGIN \n", 10000000)) + result, rest := Decode(input) + if result != nil || !reflect.DeepEqual(rest, input) { + t.Errorf("Encode of %#v decoded as %#v", input, rest) } } |