Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanner: Don't call unread() after reading EOF. #239

Merged
merged 2 commits into from
Apr 3, 2018

Conversation

octo
Copy link
Contributor

@octo octo commented Mar 19, 2018

For example, the (Go quoted) input \"\\00 creates the following stack trace:

panic: bytes.Buffer: UnreadRune: previous operation was not a successful ReadRune

goroutine 1 [running]:
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).unread(0xc420090270)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:112 +0x245
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanDigits(0xc420090270, 0x0, 0x8, 0x3, 0x5c2005b740)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:557 +0x1ba
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanEscape(0xc420090270, 0xc40000005c)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:520 +0x181
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanString(0xc420090270)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:504 +0x2c3
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).Scan(0xc420090270, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:172 +0x509
github.com/hashicorp/hcl/hcl/parser.(*Parser).scan(0xc42005bd18, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:448 +0xf4
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectKey(0xc42005bd18, 0x530aa8, 0xc42005bd18, 0xc42005bd18, 0x18, 0x50f980)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:224 +0xca
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectItem(0xc42005bd18, 0x0, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:150 +0xbf
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectList(0xc42005bd18, 0xc42000e000, 0x0, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:88 +0x139
github.com/hashicorp/hcl/hcl/parser.(*Parser).Parse(0xc42005bd18, 0xc420090270, 0x200000, 0xc42005bce0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:59 +0xf3
github.com/hashicorp/hcl/hcl/parser.Parse(0x7fca1fdd9000, 0x4, 0x200000, 0x8, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:46 +0x294
github.com/hashicorp/hcl/hcl/printer.Format(0x7fca1fdd9000, 0x4, 0x200000, 0x0, 0xc42005bef0, 0x464307, 0x4, 0xc42005bed0)
        gopath/src/github.com/hashicorp/hcl/hcl/printer/printer.go:53 +0x5b

Kudos to dvyukov/go-fuzz for finding this!

@octo octo force-pushed the scanner branch 2 times, most recently from 72e4f20 to ae5d03a Compare March 20, 2018 19:46
For example, the (Go quoted) input "\"\\00" creates the following stack
trace:

```
panic: bytes.Buffer: UnreadRune: previous operation was not a successful ReadRune

goroutine 1 [running]:
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).unread(0xc420090270)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:112 +0x245
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanDigits(0xc420090270, 0x0, 0x8, 0x3, 0x5c2005b740)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:557 +0x1ba
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanEscape(0xc420090270, 0xc40000005c)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:520 +0x181
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanString(0xc420090270)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:504 +0x2c3
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).Scan(0xc420090270, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:172 +0x509
github.com/hashicorp/hcl/hcl/parser.(*Parser).scan(0xc42005bd18, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:448 +0xf4
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectKey(0xc42005bd18, 0x530aa8, 0xc42005bd18, 0xc42005bd18, 0x18, 0x50f980)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:224 +0xca
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectItem(0xc42005bd18, 0x0, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:150 +0xbf
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectList(0xc42005bd18, 0xc42000e000, 0x0, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:88 +0x139
github.com/hashicorp/hcl/hcl/parser.(*Parser).Parse(0xc42005bd18, 0xc420090270, 0x200000, 0xc42005bce0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:59 +0xf3
github.com/hashicorp/hcl/hcl/parser.Parse(0x7fca1fdd9000, 0x4, 0x200000, 0x8, 0x0, 0x0)
        gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:46 +0x294
github.com/hashicorp/hcl/hcl/printer.Format(0x7fca1fdd9000, 0x4, 0x200000, 0x0, 0xc42005bef0, 0x464307, 0x4, 0xc42005bed0)
        gopath/src/github.com/hashicorp/hcl/hcl/printer/printer.go:53 +0x5b
```
This fixes the TestScanDigitsUnread() unit test.
@mitchellh
Copy link
Contributor

Thanks!

@mitchellh mitchellh merged commit 061bf37 into hashicorp:master Apr 3, 2018
@octo octo deleted the scanner branch April 4, 2018 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants