diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2022-11-22 10:37:05 +0000 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2022-11-22 11:48:19 +0100 |
| commit | 1c8e10bcebe7f39ca238a5dfbd1bd92c9faa39b8 (patch) | |
| tree | e75bc132bcfd3e2613420f779efe33ea8c31680a | |
| parent | 1c576c232f825266983096180b3603005edc458e (diff) | |
prog: handle broken base64 strings
Currently it can fail if there's never a closing quote.
Add a test to verify this behavior.
| -rw-r--r-- | prog/encoding.go | 4 | ||||
| -rw-r--r-- | prog/encoding_test.go | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/prog/encoding.go b/prog/encoding.go index 33983fb47..5c4be432e 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -978,15 +978,15 @@ func (p *parser) deserializeData() ([]byte, bool, error) { // Read Base64 data. p.consume() var rawData []byte - for p.Char() != '"' { + for !p.EOF() && p.Char() != '"' { v := p.consume() rawData = append(rawData, v) } + p.Parse('"') decoded, err := DecodeB64(rawData) if err != nil { return nil, false, fmt.Errorf("data arg is corrupt: %v", err) } - p.Parse('"') return decoded, true, nil } val := "" diff --git a/prog/encoding_test.go b/prog/encoding_test.go index 4cb836922..73c2cabcc 100644 --- a/prog/encoding_test.go +++ b/prog/encoding_test.go @@ -331,6 +331,10 @@ func TestDeserialize(t *testing.T) { In: `test$opt2(0x0) (fail_nth: 0)`, Out: `test$opt2(0x0)`, }, + { + In: `test$str2(&(0x7f0000000000)="$eJwqrqzKTszJSS0CBAAA//8TyQPi`, + Err: `want ", got EOF`, + }, }) } |
