aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/pem/pem.go4
-rw-r--r--src/encoding/pem/pem_test.go4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/encoding/pem/pem.go b/src/encoding/pem/pem.go
index 2356096ade..1da60d3227 100644
--- a/src/encoding/pem/pem.go
+++ b/src/encoding/pem/pem.go
@@ -116,11 +116,11 @@ func Decode(data []byte) (p *Block, rest []byte) {
var typeLine []byte
var consumed int
typeLine, rest, consumed = getLine(rest)
+ endIndex -= consumed
+ endTrailerIndex -= consumed
if !bytes.HasSuffix(typeLine, pemEndOfLine) {
continue
}
- endIndex -= consumed
- endTrailerIndex -= consumed
typeLine = typeLine[0 : len(typeLine)-len(pemEndOfLine)]
p = &Block{
diff --git a/src/encoding/pem/pem_test.go b/src/encoding/pem/pem_test.go
index 5bdc2f66a7..fa6e8ba62b 100644
--- a/src/encoding/pem/pem_test.go
+++ b/src/encoding/pem/pem_test.go
@@ -736,3 +736,7 @@ func FuzzDecode(f *testing.F) {
Decode(data)
})
}
+
+func TestMissingEndTrailer(t *testing.T) {
+ Decode([]byte{0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xa, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20})
+}