1
0
mirror of https://github.com/golang/go synced 2024-11-18 02:34:46 -07:00

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>
This commit is contained in:
Russ Cox 2017-04-03 14:34:51 -04:00
parent 69fe9ea43e
commit 1d6a499cc0

View File

@ -206,11 +206,20 @@ func TestLineBreaker(t *testing.T) {
} }
func TestFuzz(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 { testRoundtrip := func(block Block) bool {
if isBad(block.Type) {
return true
}
for key, val := range block.Headers { 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 { // Reject bad key/val.
// Keys with colons or newlines cannot be encoded. // Also, keys with colons cannot be encoded, because : is the key: val separator.
// Keys/values with surrounding spaces might lose theirs. if isBad(key) || isBad(val) || strings.Contains(key, ":") {
return true return true
} }
} }