From: claudio Date: Tue, 4 Jan 2022 15:25:05 +0000 (+0000) Subject: Try to handle possible vm_register() failures and return an error back X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ec4b63a0df5b03c2e1dc0107b77c6af50227dcc4;p=openbsd Try to handle possible vm_register() failures and return an error back to the caller instead of most probably crashing because of a NULL pointer access. This fixes also another -Wunused-but-set-variable warning. OK benno@ dv@ --- diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index 6a2d55db527..eb75b4c5878 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.102 2021/11/29 05:17:35 deraadt Exp $ */ +/* $OpenBSD: vmm.c,v 1.103 2022/01/04 15:25:05 claudio Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -102,7 +102,7 @@ int vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) { struct privsep *ps = p->p_ps; - int res = 0, cmd = 0, verbose, ret; + int res = 0, cmd = 0, verbose; struct vmd_vm *vm = NULL; struct vm_terminate_params vtp; struct vmop_id vid; @@ -278,8 +278,12 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) case IMSG_VMDOP_RECEIVE_VM_REQUEST: IMSG_SIZE_CHECK(imsg, &vmc); memcpy(&vmc, imsg->data, sizeof(vmc)); - ret = vm_register(ps, &vmc, &vm, - imsg->hdr.peerid, vmc.vmc_owner.uid); + if (vm_register(ps, &vmc, &vm, + imsg->hdr.peerid, vmc.vmc_owner.uid) != 0) { + res = errno; + cmd = IMSG_VMDOP_START_VM_RESPONSE; + break; + } vm->vm_tty = imsg->fd; vm->vm_state |= VM_STATE_RECEIVED; vm->vm_state |= VM_STATE_PAUSED; @@ -328,6 +332,7 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) } if (id == 0) id = imsg->hdr.peerid; + /* FALLTHROUGH */ case IMSG_VMDOP_PAUSE_VM_RESPONSE: case IMSG_VMDOP_UNPAUSE_VM_RESPONSE: case IMSG_VMDOP_TERMINATE_VM_RESPONSE: