Commit 1d6a499c authored by Russ Cox's avatar Russ Cox

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 69fe9ea4
...@@ -206,11 +206,20 @@ func TestLineBreaker(t *testing.T) { ...@@ -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
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment