in case of incorrect option parsing. --- My former patch introduced a regression: https://bugzilla.redhat.com/show_bug.cgi?id=605660
tools/virsh.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 38 insertions(+), 14 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index b42aac4..42ebd55 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -706,8 +706,10 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(ctl->name); - if (vshCommandOptString(cmd, "name", &name) <= 0) + if (vshCommandOptString(cmd, "name", &name) < 0) { + vshError(ctl, "%s", _("Please specify valid connection URI")); return FALSE; + } ctl->name = vshStrdup(ctl, name); if (!ro) { @@ -773,7 +775,7 @@ static int cmdConsole(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; - int ret; + int ret = FALSE; const char *name = NULL; if (!vshConnectionUsability(ctl, ctl->conn)) @@ -782,11 +784,14 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return FALSE; - if (vshCommandOptString(cmd, "devname", &name) < 0) - return FALSE; + if (vshCommandOptString(cmd, "devname", &name) < 0) { + vshError(ctl, "%s", _("Invalid devname")); + goto cleanup; + } ret = cmdRunConsole(ctl, dom, name); +cleanup: virDomainFree(dom); return ret; } @@ -2410,8 +2415,10 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) const char *type = NULL; int vcpus; - if (vshCommandOptString(cmd, "type", &type) < 0) + if (vshCommandOptString(cmd, "type", &type) < 0) { + vshError(ctl, "%s", _("Invalid type")); return FALSE; + } if (!vshConnectionUsability(ctl, ctl->conn)) return FALSE; @@ -2856,8 +2863,10 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return FALSE; - if (vshCommandOptInt(cmd, "count", &count) < 0) - return FALSE; + if (vshCommandOptInt(cmd, "count", &count) < 0) { + vshError(ctl, "%s", _("Invalid number of virtual CPUs")); + goto cleanup; + } if (!flags) { if (virDomainSetVcpus(dom, count) != 0) { @@ -3705,8 +3714,10 @@ doMigrate (void *opaque) if (vshCommandOptString(cmd, "desturi", &desturi) <= 0 || vshCommandOptString(cmd, "migrateuri", &migrateuri) < 0 || - vshCommandOptString(cmd, "dname", &dname) < 0) + vshCommandOptString(cmd, "dname", &dname) < 0) { + vshError(ctl, "%s", _("missing argument")); goto out; + } if (vshCommandOptBool (cmd, "live")) flags |= VIR_MIGRATE_LIVE; @@ -5509,8 +5520,10 @@ static int buildPoolXML(const vshCmd *cmd, const char **retname, char **xml) { vshCommandOptString(cmd, "source-dev", &srcDev) < 0 || vshCommandOptString(cmd, "source-name", &srcName) < 0 || vshCommandOptString(cmd, "source-format", &srcFormat) < 0 || - vshCommandOptString(cmd, "target", &target) < 0) + vshCommandOptString(cmd, "target", &target) < 0) { + vshError(NULL, "%s", _("missing argument")); goto cleanup; + } virBufferVSprintf(&buf, "<pool type='%s'>\n", type); virBufferVSprintf(&buf, " <name>%s</name>\n", name); @@ -6314,8 +6327,10 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED) if (vshCommandOptString(cmd, "type", &type) <= 0 || vshCommandOptString(cmd, "host", &host) < 0 || - vshCommandOptString(cmd, "initiator", &initiator) < 0) + vshCommandOptString(cmd, "initiator", &initiator) < 0) { + vshError(ctl,"%s", _("missing argument")); return FALSE; + } if (!vshConnectionUsability(ctl, ctl->conn)) return FALSE; @@ -6386,8 +6401,10 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED) if (vshCommandOptString(cmd, "type", &type) <= 0) return FALSE; - if (vshCommandOptString(cmd, "srcSpec", &srcSpecFile) < 0) + if (vshCommandOptString(cmd, "srcSpec", &srcSpecFile) < 0) { + vshError(ctl, "%s", _("missing option")); return FALSE; + } if (!vshConnectionUsability(ctl, ctl->conn)) return FALSE; @@ -8862,8 +8879,10 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) vshCommandOptString(cmd, "target", &target) < 0 || vshCommandOptString(cmd, "mac", &mac) < 0 || vshCommandOptString(cmd, "script", &script) < 0 || - vshCommandOptString(cmd, "model", &model) < 0) + vshCommandOptString(cmd, "model", &model) < 0) { + vshError(ctl, "missing argument"); goto cleanup; + } /* check interface type */ if (STREQ(type, "network")) { @@ -8969,8 +8988,10 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "type", &type) <= 0) goto cleanup; - if (vshCommandOptString(cmd, "mac", &mac) < 0) + if (vshCommandOptString(cmd, "mac", &mac) < 0) { + vshError(ctl, "%s", _("missing option")); goto cleanup; + } doc = virDomainGetXMLDesc(dom, 0); if (!doc) @@ -9120,6 +9141,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) vshCommandOptString(cmd, "type", &type) < 0 || vshCommandOptString(cmd, "mode", &mode) < 0 || vshCommandOptString(cmd, "sourcetype", &stype) < 0) { + vshError(ctl, "%s", _("missing option")); goto cleanup; } @@ -11272,8 +11294,10 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, if (vshCommandOptString(cmd, optname, &n) <= 0) return NULL; - if (vshCommandOptString(cmd, pooloptname, &p) < 0) + if (vshCommandOptString(cmd, pooloptname, &p) < 0) { + vshError(ctl, "%s", _("missing option")); return NULL; + } if (p) pool = vshCommandOptPoolBy(ctl, cmd, pooloptname, name, flag); -- 1.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list