-/* $OpenBSD: vmctl.c,v 1.52 2018/07/11 13:19:47 reyk Exp $ */
+/* $OpenBSD: vmctl.c,v 1.53 2018/07/11 21:29:05 reyk Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
warnx("starting without network interfaces");
}
- vmc = calloc(1, sizeof(struct vmop_create_params));
- if (vmc == NULL)
+ if ((vmc = calloc(1, sizeof(struct vmop_create_params))) == NULL)
return (ENOMEM);
vmc->vmc_flags = flags;
vcp->vcp_id = start_id;
for (i = 0 ; i < ndisks; i++)
- strlcpy(vcp->vcp_disks[i], disks[i], VMM_MAX_PATH_DISK);
+ if (strlcpy(vcp->vcp_disks[i], disks[i],
+ sizeof(vcp->vcp_disks[i])) >=
+ sizeof(vcp->vcp_disks[i]))
+ errx(1, "disk path too long");
for (i = 0 ; i < nnics; i++) {
vmc->vmc_ifflags[i] = VMIFF_UP;
if (strcmp(".", nics[i]) == 0) {
/* Add a "local" interface */
- strlcpy(vmc->vmc_ifswitch[i], "", IF_NAMESIZE);
+ (void)strlcpy(vmc->vmc_ifswitch[i], "",
+ sizeof(vmc->vmc_ifswitch[i]));
vmc->vmc_ifflags[i] |= VMIFF_LOCAL;
} else {
/* Add an interface to a switch */
- strlcpy(vmc->vmc_ifswitch[i], nics[i], IF_NAMESIZE);
+ if (strlcpy(vmc->vmc_ifswitch[i], nics[i],
+ sizeof(vmc->vmc_ifswitch[i])) >=
+ sizeof(vmc->vmc_ifswitch[i]))
+ errx(1, "interface name too long");
}
}
if (name != NULL) {
errx(1, "invalid VM name");
}
- strlcpy(vcp->vcp_name, name, VMM_MAX_NAME_LEN);
+ if (strlcpy(vcp->vcp_name, name,
+ sizeof(vcp->vcp_name)) >= sizeof(vcp->vcp_name))
+ errx(1, "vm name too long");
}
if (kernel != NULL)
- strlcpy(vcp->vcp_kernel, kernel, VMM_MAX_KERNEL_PATH);
-
+ if (strlcpy(vcp->vcp_kernel, kernel,
+ sizeof(vcp->vcp_kernel)) >= sizeof(vcp->vcp_kernel))
+ errx(1, "kernel name too long");
if (iso != NULL)
- strlcpy(vcp->vcp_cdrom, iso, VMM_MAX_PATH_CDROM);
+ if (strlcpy(vcp->vcp_cdrom, iso,
+ sizeof(vcp->vcp_cdrom)) >= sizeof(vcp->vcp_cdrom))
+ errx(1, "cdrom name too long");
imsg_compose(ibuf, IMSG_VMDOP_START_VM_REQUEST, 0, 0, -1,
vmc, sizeof(struct vmop_create_params));