-
Notifications
You must be signed in to change notification settings - Fork 790
fix: nil pointer dereference panic in shellAction #4453
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
base: master
Are you sure you want to change the base?
Conversation
|
This was to fix the following error I get: |
|
I have tested and confirmed this works now. |
|
Ci fail seems like a flake: |
What paths? |
|
@AkihiroSuda this is to fix an actual nil reference crash I can reproduce reliably on the current master branch without this PR applied. The issue occurs when you have an invalid config. The config validation fails and config is nil. The err is not checked and the program therefore hits a nil dereference exception when trying to start the vm (with lima or limactl shell). |
|
|
@AkihiroSuda Here is the broken config: images:
- location: "https://cloud.debian.org/images/cloud/sid/daily/latest/debian-sid-genericcloud-arm64-daily.qcow2"
arch: "aarch64"
mounts: []
containerd:
system: false
user: false
# The problem: mountType 9p is incompatible with VZ driver
# On Apple Silicon, vmType defaults to "vz" but 9p only works with QEMU
mountType: 9p
cpus: 11
memory: 10GiB
provision:
- mode: system
script: |
#!/bin/bash
set -eux -o pipefail
command -v docker >/dev/null 2>&1 && exit 0
export DEBIAN_FRONTEND=noninteractive
apt update
apt-get install -y docker.io
portForwards:
- guestSocket: "/var/run/docker.sock"
hostSocket: "{{.Dir}}/sock/docker.sock"This config was originally created using QEMU (which supports 9p mounts), but changed After the PR is applied, |
The shellAction function panics with a nil pointer dereference when attempting
to shell into an instance that has configuration validation errors:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x98 pc=0x...]
This occurs because store.Inspect() returns an instance with inst.Config set to
nil when validation fails, but the code at lines 171, 252-256 accesses
inst.Config fields without checking for nil.
Example scenario: An instance created with Lima 1.2.1 using QEMU has mountType:
9p in its config. On newer Lima versions, if vmType defaults to vz (or is set
explicitly), the config fails validation since VZ only supports reverse-sshfs or
virtiofs mount types. The validation error leaves inst.Config as nil, causing
the panic.
This fix adds an early nil check for inst.Config (after store.Inspect at line
90) to return a clear error message instead of panicking:
instance "docker" has configuration errors: field 'mountType' must be
"reverse-sshfs" or "virtiofs" for VZ driver, got "9p"
Signed-off-by: Christian Stewart <[email protected]>
7c3e665 to
4aa3d95
Compare
|
@AkihiroSuda Thank you for your review. According to your comments the PR description + commit message are fixed and the PR is now only 6 lines long checking the error. |
The shellAction function panics with a nil pointer dereference when attempting to shell into an instance that has configuration validation errors:
This occurs because store.Inspect() returns an instance with inst.Config set to nil when validation fails, but the code at lines 171, 252-256 accesses inst.Config fields without checking for nil.
Example scenario: An instance created with Lima 1.2.1 using QEMU has mountType: 9p in its config. On newer Lima versions, if vmType defaults to vz (or is set explicitly), the config fails validation since VZ only supports reverse-sshfs or
virtiofs mount types. The validation error leaves inst.Config as nil, causing the panic.
This fix adds an early nil check for inst.Config (after store.Inspect at line 90) to return a clear error message instead of panicking: