Skip to content

x/tools/gopls: nil deref in 'go vendor' Snapshot.GoCommandInvocation #73891

Open
@adonovan

Description

@adonovan
#!stacks
"sigpanic" && "cache.(*Snapshot).GoCommandInvocation:+5"

Issue created by stacks.

func (s *Snapshot) GoCommandInvocation(allowNetwork AllowNetwork, dir, verb string, args []string, env ...string) (_ *gocommand.Invocation, cleanup func(), _ error) {
	inv := &gocommand.Invocation{
		Verb:       verb,
		Args:       args,
		WorkingDir: dir,
		Env:        append(s.view.Env(), env...), // <--- nil deref

called from here:

func (c *commandHandler) Vendor(ctx context.Context, args command.URIArg) error {
	return c.run(ctx, commandConfig{ ... 
	}, func(ctx context.Context, deps commandDeps) error 
...
		inv, cleanupInvocation, err := deps.snapshot.GoCommandInvocation(cache.NetworkOK, args.URI.DirPath(), "mod", []string{"vendor"})

The crash implies that either deps.snapshot or deps.snapshot.view is nil. The first cannot be the case because of the early return in c.run. The second cannot be the case because it's an immutable field of Snapshot that is non-nil at construction. So I think this is yet another case of memory corruption.

This stack wY83jw was reported by telemetry:

golang.org/x/tools/gopls@v0.18.1 go1.24.0 darwin/arm64 neovim,vscode (5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions