aboutsummaryrefslogtreecommitdiffstats
path: root/vm/qemu
diff options
context:
space:
mode:
authorSungwoo Kim <contact@sung-woo.kim>2024-02-20 00:56:30 -0500
committerAleksandr Nogikh <nogikh@google.com>2024-02-21 14:46:23 +0000
commit3eb4f0c2a392b15406af944af98065c12634affd (patch)
tree9fe575729b92dd5a7522534eced2fd648e9452d8 /vm/qemu
parent4622e01246e4f835db558e8c3144c7ca6ea767e6 (diff)
vm/qemu.go: fix nil-ptr-deref in ctor
os.Stat() may return (nil, err) if it fails to open a file. So, the code below wrongly validates st as it will be always nil if err != nil, causing nil pointer dereference in st.Size(). ``` if st, err := os.Stat(inst.image); err != nil && st.Size() == 0 { ``` To fix this, this patch allows st.Size() only if err == nil.
Diffstat (limited to 'vm/qemu')
-rw-r--r--vm/qemu/qemu.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go
index 9cb7f565b..b3f1ca0bc 100644
--- a/vm/qemu/qemu.go
+++ b/vm/qemu/qemu.go
@@ -376,7 +376,7 @@ func (pool *Pool) ctor(workdir, sshkey, sshuser string, index int) (vmimpl.Insta
sshuser: sshuser,
diagnose: make(chan bool, 1),
}
- if st, err := os.Stat(inst.image); err != nil && st.Size() == 0 {
+ if st, err := os.Stat(inst.image); err == nil && st.Size() == 0 {
// Some kernels may not need an image, however caller may still
// want to pass us a fake empty image because the rest of syzkaller
// assumes that an image is mandatory. So if the image is empty, we ignore it.