Skip to content

x/tools/gopls: nil (or invalid) *ExprStmt pointer in AST #76747

Description

@adonovan
#!stacks
"sigpanic" && "unusedresult.run.func1:+1"

Issue created by stacks.

func run(pass *analysis.Pass) (any, error) {
...
	inspect.Preorder(nodeFilter, func(n ast.Node) {
		call, ok := ast.Unparen(n.(*ast.ExprStmt).X).(*ast.CallExpr) // panics loading .X field
TEXT golang.org/x/tools/go/analysis/passes/unusedresult.run.func1(SB) go/analysis/passes/unusedresult/unusedresult.go
...
  unusedresult.go:142   0x9a9f8f                55                      PUSHQ BP                                                                                                                      
  unusedresult.go:142   0x9a9f90                4889e5                  MOVQ SP, BP                                                                                                                   
  unusedresult.go:142   0x9a9f93                4881ecd8000000          SUBQ $0xd8, SP                                                                                                                
  unusedresult.go:142   0x9a9f9a                48898424e8000000        MOVQ AX, 0xe8(SP)                                                                                                             
  unusedresult.go:142   0x9a9fa2                48899c24f0000000        MOVQ BX, 0xf0(SP)                                                                                                             
  unusedresult.go:142   0x9a9faa                488b7210                MOVQ 0x10(DX), SI                                                                                                             
  unusedresult.go:143   0x9a9fae                488d3d8b7ac700          LEAQ go:itab.*go/ast.ExprStmt,go/ast.Node(SB), DI                                                                             
  unusedresult.go:143   0x9a9fb5                4839f8                  CMPQ AX, DI                                                                                                                   
  unusedresult.go:143   0x9a9fb8                0f856d030000            JNE 0x9aa32b                                                                                                                  
  unusedresult.go:143   0x9a9fbe                488b0b                  MOVQ 0(BX), CX            // SEGV loading first word of ExprStmt.X
  unusedresult.go:143   0x9a9fc1                488b7b08                MOVQ 0x8(BX), DI                                                                                                              

If the ExprStmt pointer is nil, that means the parser has a bug or the AST has become corrupted. If it is non-nil, then we have memory corruption.

This stack NVOHJQ was reported by telemetry:

golang.org/x/tools/gopls@v0.20.0 go1.25.2 linux/amd64 gopls.client=vscode (1)

Use this command to reproduce the executable:
(HOME=$(mktemp -d); GOOS=linux GOARCH=amd64 GOTOOLCHAIN=go1.25.2 go install golang.org/x/tools/gopls@v0.20.0 && find $HOME/go/bin -type f)
To disassemble: go tool objdump exe | less

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/memory-corruption"can't happen" gopls crashes (races, unsafe, miscompile, runtime bugs, faulty HW)gopls/telemetry-wins

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions