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

x/tools/go/packages: nil pointer dereference #69524

Closed
bryancua opened this issue Sep 18, 2024 · 3 comments
Closed

x/tools/go/packages: nil pointer dereference #69524

bryancua opened this issue Sep 18, 2024 · 3 comments
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@bryancua
Copy link

bryancua commented Sep 18, 2024

Go version

go version go1.23.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOOS='darwin'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/lr/ftztsqk12fv4y1q5l4zy82700000gn/T/go-build3998064584=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Ran the following program:

package main

import (
	. "golang.org/x/tools/go/packages"
)

func main() {
	cfg := &Config{
		Mode: NeedName | NeedFiles | NeedCompiledGoFiles | NeedImports | NeedTypes | NeedTypesSizes | NeedSyntax |
			NeedTypesInfo | NeedDeps,
	}

	// Load the files.
	pkgs, err := Load(cfg, "flag")
	if err != nil {
		panic(err)
	}
	if PrintErrors(pkgs) > 0 {
		panic(err)
	}
}

What did you see happen?

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x102957f14]

goroutine 106 [running]:
go/types.(*Checker).handleBailout(0x140001fb500, 0x140001cfbb8)
        /usr/local/go/src/go/types/check.go:404 +0x9c
panic({0x102a402c0?, 0x102bca540?})
        /usr/local/go/src/runtime/panic.go:785 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x102a7d8c8, 0x102bcd360})
        /usr/local/go/src/go/types/sizes.go:229 +0x314
go/types.(*Config).sizeof(...)
        /usr/local/go/src/go/types/sizes.go:334
go/types.representableConst.func1({0x102a7d8c8?, 0x102bcd360?})
        /usr/local/go/src/go/types/const.go:77 +0x90
go/types.representableConst({0x102a7f390, 0x102bc2f00}, 0x140001fb500, 0x102bcd360, 0x140001ce9d8)
        /usr/local/go/src/go/types/const.go:93 +0x134
go/types.(*Checker).representation(0x140001fb500, 0x140001eb480, 0x102bcd360)
        /usr/local/go/src/go/types/const.go:257 +0x68
go/types.(*Checker).implicitTypeAndValue(0x140001fb500, 0x140001eb480, {0x102a7d8c8, 0x102bcd360})
        /usr/local/go/src/go/types/expr.go:377 +0x304
go/types.(*Checker).convertUntyped(0x140001fb500, 0x140001eb480, {0x102a7d8c8, 0x102bcd360})
        /usr/local/go/src/go/types/const.go:290 +0x30
go/types.(*Checker).matchTypes(0x140001fb500, 0x140001eb440, 0x140001eb480)
        /usr/local/go/src/go/types/expr.go:928 +0x7c
go/types.(*Checker).binary(0x140001fb500, 0x140001eb440, {0x102a7e500, 0x140001b1a40}, {0x102a7e5c0, 0x140001e72e0}, {0x102a7eb00, 0x140001e7300}, 0x28, 0x71c2)
        /usr/local/go/src/go/types/expr.go:802 +0x114
go/types.(*Checker).exprInternal(0x140001fb500, 0x0, 0x140001eb440, {0x102a7e500, 0x140001b1a40}, {0x0, 0x0})
        /usr/local/go/src/go/types/expr.go:1452 +0x1d4
go/types.(*Checker).rawExpr(0x140001fb500, 0x0, 0x140001eb440, {0x102a7e500?, 0x140001b1a40?}, {0x0?, 0x0?}, 0x0)
        /usr/local/go/src/go/types/expr.go:981 +0x120
go/types.(*Checker).expr(0x140001fb500, 0x102a7dc60?, 0x140001eb440, {0x102a7e500?, 0x140001b1a40?})
        /usr/local/go/src/go/types/expr.go:1549 +0x38
go/types.(*Checker).stmt(0x140001fb500, 0x0, {0x102a7e920, 0x140001ea700})
        /usr/local/go/src/go/types/stmt.go:579 +0xa3c
go/types.(*Checker).stmtList(0x140001fb500, 0x0, {0x140001e7460?, 0x140001fb500?, 0x3?})
        /usr/local/go/src/go/types/stmt.go:121 +0x88
go/types.(*Checker).funcBody(0x140001fb500, 0x102a7e5c0?, {0x140001927a8?, 0x102a81458?}, 0x140001eb180, 0x140001b1ad0, {0x0?, 0x0?})
        /usr/local/go/src/go/types/stmt.go:41 +0x218
go/types.(*Checker).funcDecl.func1()
        /usr/local/go/src/go/types/decl.go:888 +0x44
go/types.(*Checker).processDelayed(0x140001fb500, 0x0)
        /usr/local/go/src/go/types/check.go:516 +0x12c
go/types.(*Checker).checkFiles(0x140001fb500, {0x1400018e1b8, 0x1, 0x1})
        /usr/local/go/src/go/types/check.go:462 +0x1b4
go/types.(*Checker).Files(0x140000f4000?, {0x1400018e1b8?, 0x140001a0780?, 0x6?})
        /usr/local/go/src/go/types/check.go:422 +0x80
golang.org/x/tools/go/packages.(*loader).loadPackage(0x140000f4000, 0x140000758f0)
        /***/golang.org/x/tools@v0.9.1/go/packages/packages.go:1052 +0x858
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
        /***/golang.org/x/tools@v0.9.1/go/packages/packages.go:851 +0x178
sync.(*Once).doSlow(0x0?, 0x0?)
        /usr/local/go/src/sync/once.go:76 +0xf8
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:67
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
        /***/golang.org/x/tools@v0.9.1/go/packages/packages.go:839 +0x48
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
        /***/golang.org/x/tools@v0.9.1/go/packages/packages.go:846 +0x30
created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 8
        /***/golang.org/x/tools@v0.9.1/go/packages/packages.go:845 +0x84

What did you expect to see?

Exit code 0

The code runs properly on 1.22

@seankhliao seankhliao changed the title golang.org/x/tools/go/packages: nil pointer dereference x/tools/go/packages: nil pointer dereference Sep 18, 2024
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 18, 2024
@gopherbot gopherbot added this to the Unreleased milestone Sep 18, 2024
@findleyr
Copy link
Member

What is your version of x/tools? This looks like #62167.

@bryancua
Copy link
Author

Thanks. I should have checked that first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants