diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-09-10 10:39:27 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-09-10 10:39:27 +0000 |
commit | 332f1f0803d7de54f78da8ad72a2c0ecb789f912 (patch) | |
tree | c4cb1385734d7f09f829be0d6d37ec28c61867eb /usr.sbin | |
parent | a6e0aea87a35e836839da9a92aef8797622d1f68 (diff) |
vmd(8) clould close file descriptor 0 as not all fd fields were
properly initialized with -1. Also avoid closing -1.
OK mlarkin@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/vmd/vmd.c | 8 | ||||
-rw-r--r-- | usr.sbin/vmd/vmm.c | 24 |
2 files changed, 17 insertions, 15 deletions
diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index ac4d1635bd4..25d19dc7a7f 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.99 2018/09/10 10:36:01 bluhm Exp $ */ +/* $OpenBSD: vmd.c,v 1.100 2018/09/10 10:39:26 bluhm Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -1249,11 +1249,11 @@ vm_register(struct privsep *ps, struct vmop_create_params *vmc, vm->vm_paused = 0; vm->vm_user = usr; - for (i = 0; i < vcp->vcp_ndisks; i++) + for (i = 0; i < VMM_MAX_DISKS_PER_VM; i++) vm->vm_disks[i] = -1; - for (i = 0; i < vcp->vcp_nnics; i++) { + for (i = 0; i < VMM_MAX_NICS_PER_VM; i++) vm->vm_ifs[i].vif_fd = -1; - + for (i = 0; i < vcp->vcp_nnics; i++) { if ((sw = switch_getbyname(vmc->vmc_ifswitch[i])) != NULL) { /* inherit per-interface flags from the switch */ vmc->vmc_ifflags[i] |= (sw->sw_flags & VMIFF_OPTMASK); diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index 4e96fc25e42..7757856323f 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.88 2018/07/13 08:42:49 reyk Exp $ */ +/* $OpenBSD: vmm.c,v 1.89 2018/09/10 10:39:26 bluhm Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -646,20 +646,22 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid) close(vm->vm_disks[i]); vm->vm_disks[i] = -1; } - for (i = 0 ; i < vcp->vcp_nnics; i++) { close(vm->vm_ifs[i].vif_fd); vm->vm_ifs[i].vif_fd = -1; } - - close(vm->vm_kernel); - vm->vm_kernel = -1; - - close(vm->vm_cdrom); - vm->vm_cdrom = -1; - - close(vm->vm_tty); - vm->vm_tty = -1; + if (vm->vm_kernel != -1) { + close(vm->vm_kernel); + vm->vm_kernel = -1; + } + if (vm->vm_cdrom != -1) { + close(vm->vm_cdrom); + vm->vm_cdrom = -1; + } + if (vm->vm_tty != -1) { + close(vm->vm_tty); + vm->vm_tty = -1; + } /* read back the kernel-generated vm id from the child */ if (read(fds[0], &vcp->vcp_id, sizeof(vcp->vcp_id)) != |