diff options
author | Russ Cox <rsc@golang.org> | 2017-04-03 14:34:51 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2017-04-03 18:46:56 +0000 |
commit | 1d6a499cc02012275b3c172dc98a143e49fb8ddc (patch) | |
tree | ef9946d8f6f8ba37d9c8a3d9a2121b3b945a4743 /src/encoding/pem | |
parent | 69fe9ea43e66552c11f2b87cdf63a39448b46287 (diff) | |
download | go-1d6a499cc02012275b3c172dc98a143e49fb8ddc.tar.gz go-1d6a499cc02012275b3c172dc98a143e49fb8ddc.zip |
encoding/pem: yet another fuzz fake failure
Fixes #19829.
Change-Id: I8500fd73c37b504d6ea25f5aff7017fbc0718570
Reviewed-on: https://go-review.googlesource.com/39314
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/encoding/pem')
-rw-r--r-- | src/encoding/pem/pem_test.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/encoding/pem/pem_test.go b/src/encoding/pem/pem_test.go index 7ab0e8f61d..1a1250a52f 100644 --- a/src/encoding/pem/pem_test.go +++ b/src/encoding/pem/pem_test.go @@ -206,11 +206,20 @@ func TestLineBreaker(t *testing.T) { } func TestFuzz(t *testing.T) { + // PEM is a text-based format. Assume header fields with leading/trailing spaces + // or embedded newlines will not round trip correctly and don't need to be tested. + isBad := func(s string) bool { + return strings.ContainsAny(s, "\r\n") || strings.TrimSpace(s) != s + } + testRoundtrip := func(block Block) bool { + if isBad(block.Type) { + return true + } for key, val := range block.Headers { - if strings.ContainsAny(key, ":\r\n") || strings.ContainsAny(val, "\r\n") || strings.TrimSpace(key) != key || strings.TrimSpace(val) != val { - // Keys with colons or newlines cannot be encoded. - // Keys/values with surrounding spaces might lose theirs. + // Reject bad key/val. + // Also, keys with colons cannot be encoded, because : is the key: val separator. + if isBad(key) || isBad(val) || strings.Contains(key, ":") { return true } } |