From 8496c967314a96d73856d532a5b3aa8419dab477 Mon Sep 17 00:00:00 2001 From: Mike Larkin Date: Tue, 10 May 2016 11:00:55 +0000 Subject: move some argument checking from vmmaction() to start_vm() from a diff posted to tech@ by Fabien Siron, thanks. --- usr.sbin/vmctl/main.c | 16 +--------------- usr.sbin/vmctl/vmctl.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c index 5dc4b25522b..83b6fab3b8f 100644 --- a/usr.sbin/vmctl/main.c +++ b/usr.sbin/vmctl/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.16 2016/04/25 15:14:34 mlarkin Exp $ */ +/* $OpenBSD: main.c,v 1.17 2016/05/10 11:00:54 mlarkin Exp $ */ /* * Copyright (c) 2015 Reyk Floeter @@ -188,20 +188,6 @@ vmmaction(struct parse_result *res) switch (res->action) { case CMD_START: - /* XXX validation should be done in start_vm() */ - if (res->size < 1) - errx(1, "specified memory size too small"); - if (res->path == NULL) - errx(1, "no kernel specified"); - if (res->ndisks > VMM_MAX_DISKS_PER_VM) - errx(1, "too many disks"); - else if (res->ndisks == 0) - warnx("starting without disks"); - if (res->nifs == -1) - res->nifs = 0; - if (res->nifs == 0) - warnx("starting without network interfaces"); - ret = start_vm(res->name, res->size, res->nifs, res->ndisks, res->disks, res->path); if (ret) { diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c index d21151b78c0..462a82a1a13 100644 --- a/usr.sbin/vmctl/vmctl.c +++ b/usr.sbin/vmctl/vmctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.c,v 1.14 2016/05/10 10:49:22 mlarkin Exp $ */ +/* $OpenBSD: vmctl.c,v 1.15 2016/05/10 11:00:54 mlarkin Exp $ */ /* * Copyright (c) 2014 Mike Larkin @@ -67,6 +67,19 @@ start_vm(const char *name, int memsize, int nnics, int ndisks, char **disks, struct vm_create_params *vcp; int i; + if (memsize < 1) + errx(1, "specified memory size too small"); + if (kernel == NULL) + errx(1, "no kernel specified"); + if (ndisks > VMM_MAX_DISKS_PER_VM) + errx(1, "too many disks"); + else if (ndisks == 0) + warnx("starting without disks"); + if (nnics == -1) + nnics = 0; + if (nnics == 0) + warnx("starting without network interfaces"); + vcp = malloc(sizeof(struct vm_create_params)); if (vcp == NULL) return (ENOMEM); -- cgit v1.2.3