Skip to content

Conversation

@paralin
Copy link

@paralin paralin commented Dec 13, 2025

The shellAction function was calling cmd.Flags() directly multiple times throughout the function instead of using the flags variable that was already captured at the beginning (line 72).

In certain execution paths, cmd.Flags() could return nil, causing a panic:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x98 pc=0x...]

This fix changes three locations to consistently use the flags variable:

  • Line 164: workDir flag access
  • Line 200: shell flag access
  • Line 211: preserve-env flag access

Additionally, adds a nil check for inst.Config before accessing it to prevent similar panics and provide clearer error messages when instances have configuration errors.

The shellAction function was calling cmd.Flags() directly multiple times
throughout the function instead of using the flags variable that was already
captured at the beginning (line 72).

In certain execution paths, cmd.Flags() could return nil, causing a panic:
  panic: runtime error: invalid memory address or nil pointer dereference
  [signal SIGSEGV: segmentation violation code=0x2 addr=0x98 pc=0x...]

This fix changes three locations to consistently use the flags variable:
- Line 164: workDir flag access
- Line 200: shell flag access
- Line 211: preserve-env flag access

Additionally, adds a nil check for inst.Config before accessing it to
prevent similar panics and provide clearer error messages when instances
have configuration errors.

Signed-off-by: Christian Stewart <[email protected]>
@paralin
Copy link
Author

paralin commented Dec 13, 2025

This was to fix the following error I get:

cjs@flame ~ % lima -v
limactl version 2.0.2

cjs@flame ~ % lima
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x98 pc=0x104f42f28]

goroutine 1 [running]:
main.shellAction(0x14000532f08, {0x140005805c0, 0x1, 0x1})
        /private/tmp/lima-20251124-4851-jwxwv0/lima-2.0.2/cmd/limactl/shell.go:165 +0x6c8
github.com/spf13/cobra.(*Command).execute(0x14000532f08, {0x14000580590, 0x1, 0x1})
        /Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/[email protected]/command.go:1015 +0x7d4
github.com/spf13/cobra.(*Command).ExecuteC(0x14000532308)
        /Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/[email protected]/command.go:1148 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/brew/Library/Caches/Homebrew/go_mod_cache/pkg/mod/github.com/spf13/[email protected]/command.go:1071
main.main()
        /private/tmp/lima-20251124-4851-jwxwv0/lima-2.0.2/cmd/limactl/main.go:50 +0x7c

@paralin
Copy link
Author

paralin commented Dec 13, 2025

I have tested and confirmed this works now.

@paralin paralin changed the title fix: avoid nil pointer dereference in shellAction fix: nil pointer dereference panic in shellAction Dec 13, 2025
@paralin
Copy link
Author

paralin commented Dec 13, 2025

Ci fail seems like a flake:

   TEST| [INFO] Uninstalling lima
  TEST| [INFO] Installing the old Lima v0.15.1
  curl: (22) The requested URL returned error: 504

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.

1 participant