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

SIGSEGV from fmt.Printf() when using go/ast.Inspect() #28729

Closed
entrope opened this issue Nov 12, 2018 · 3 comments
Closed

SIGSEGV from fmt.Printf() when using go/ast.Inspect() #28729

entrope opened this issue Nov 12, 2018 · 3 comments

Comments

@entrope
Copy link

entrope commented Nov 12, 2018

What version of Go are you using (go version)?

$ go version
go version go1.10.4 linux/amd64

Does this issue reproduce with the latest release?

Yes, similar SIGSEGV with go version devel +f58b02a29c Sun Nov 11 18:49:40 2018 +0000 linux/amd64, go version go1.11.2 linux/amd64, and go version go1.10.5 linux/amd64. (The last two fail unit tests on my Ubuntu 18.04 system, issue #28499.)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mdpoole/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mdpoole/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build101601023=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I ran the code at https://play.golang.org/p/KIUY0ozcK_8 .

What did you expect to see?

The program should terminate normally.

What did you see instead?

*ast.GenDecl at 15..32: &{ 15 import 22 [0x442300] 31}
*ast.ImportSpec at 25..30: &{  0x40c0f0  0}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0xffffffff addr=0x0 pc=0x112fa2]

goroutine 1 [running]:
main.main.func1(0x0, 0x0, 0x1785b0, 0x13f6c0)
	/tmp/sandbox244933151/main.go:25 +0x22
go/ast.inspector.Visit(0x167530, 0x0, 0x0, 0x442300, 0x1785b0, 0x442300)
	/usr/local/go/src/go/ast/walk.go:373 +0x40
go/ast.Walk(0x1780f0, 0x167530, 0x178530, 0x442320)
	/usr/local/go/src/go/ast/walk.go:367 +0x1a0
go/ast.Inspect(0x178530, 0x442320, 0x167530, 0x1317a0)
	/usr/local/go/src/go/ast/walk.go:385 +0x40
main.main()
	/tmp/sandbox244933151/main.go:22 +0x120

Program exited: status 2.
@entrope
Copy link
Author

entrope commented Nov 12, 2018

After a bit more poking, the problem is that the visitor function is being passed a nil Node. I can avoid the crash by adding an "if n == nil { return false }" to the test code, but what one supposed to do with a nil Node?

@go101
Copy link

go101 commented Nov 12, 2018

A nil node indicates the walking for children nodes is done. See the docs for details.

@entrope
Copy link
Author

entrope commented Nov 12, 2018

Well, I feel sheepish. Sorry for the noise, and thank you for the help.

@entrope entrope closed this as completed Nov 12, 2018
@golang golang locked and limited conversation to collaborators Nov 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants