Prevent null pointer deref is vm isn't found.
authordv <dv@openbsd.org>
Sun, 4 Feb 2024 14:56:45 +0000 (14:56 +0000)
committerdv <dv@openbsd.org>
Sun, 4 Feb 2024 14:56:45 +0000 (14:56 +0000)
This area of code in vmd(8) is suspect, but the null dereference
is easily avoided.

Found by smatch, reported by and ok jsg@

usr.sbin/vmd/vmd.c

index 613cdde..f821b7e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vmd.c,v 1.153 2024/01/18 14:49:59 claudio Exp $       */
+/*     $OpenBSD: vmd.c,v 1.154 2024/02/04 14:56:45 dv Exp $    */
 
 /*
  * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -527,9 +527,8 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg)
                    imsg->hdr.peerid == IMSG_AGENTX_PEERID ?
                    PROC_AGENTX : PROC_CONTROL, -1, imsg->hdr.type,
                    imsg->hdr.peerid, -1, &vir, sizeof(vir)) == -1) {
-                       log_debug("%s: GET_INFO_VM failed for vm %d, removing",
-                           __func__, vm->vm_vmid);
-                       vm_terminate(vm, __func__);
+                       if (vm)
+                               vm_terminate(vm, __func__);
                        return (-1);
                }
                break;