提交 b2e85855 编写于 作者: P Peter Krempa

virsh-snapshot: Update snapshot commands to use vshCommandOptStringReq

also avoids potential NULL pointer dereference:

$ virsh snapshot-current asdf ""
error: invalid snapshotname argument '(null)'

by removing the error message in favor of vshCommandOptStringReq
上级 351f7a2f
...@@ -207,7 +207,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) ...@@ -207,7 +207,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup; goto cleanup;
if (vshCommandOptString(cmd, "xmlfile", &from) <= 0) { if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0) {
buffer = vshStrdup(ctl, "<domainsnapshot/>"); buffer = vshStrdup(ctl, "<domainsnapshot/>");
} else { } else {
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
...@@ -431,11 +431,9 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) ...@@ -431,11 +431,9 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
if (dom == NULL) if (dom == NULL)
goto cleanup; goto cleanup;
if (vshCommandOptString(cmd, "name", &name) < 0 || if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 ||
vshCommandOptString(cmd, "description", &desc) < 0) { vshCommandOptStringReq(ctl, cmd, "description", &desc) < 0)
vshError(ctl, _("argument must not be empty"));
goto cleanup; goto cleanup;
}
virBufferAddLit(&buf, "<domainsnapshot>\n"); virBufferAddLit(&buf, "<domainsnapshot>\n");
if (name) if (name)
...@@ -443,10 +441,8 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) ...@@ -443,10 +441,8 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
if (desc) if (desc)
virBufferEscapeString(&buf, " <description>%s</description>\n", desc); virBufferEscapeString(&buf, " <description>%s</description>\n", desc);
if (vshCommandOptString(cmd, "memspec", &memspec) < 0) { if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0)
vshError(ctl, _("memspec argument must not be empty"));
goto cleanup; goto cleanup;
}
if (memspec && vshParseSnapshotMemspec(ctl, &buf, memspec) < 0) if (memspec && vshParseSnapshotMemspec(ctl, &buf, memspec) < 0)
goto cleanup; goto cleanup;
...@@ -496,10 +492,8 @@ vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd, ...@@ -496,10 +492,8 @@ vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd,
bool current = vshCommandOptBool(cmd, "current"); bool current = vshCommandOptBool(cmd, "current");
const char *snapname = NULL; const char *snapname = NULL;
if (vshCommandOptString(cmd, arg, &snapname) < 0) { if (vshCommandOptStringReq(ctl, cmd, arg, &snapname) < 0)
vshError(ctl, _("invalid argument for --%s"), arg);
return -1; return -1;
}
if (exclusive && current && snapname) { if (exclusive && current && snapname) {
vshError(ctl, _("--%s and --current are mutually exclusive"), arg); vshError(ctl, _("--%s and --current are mutually exclusive"), arg);
...@@ -703,10 +697,9 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) ...@@ -703,10 +697,9 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
if (dom == NULL) if (dom == NULL)
goto cleanup; goto cleanup;
if (vshCommandOptString(cmd, "snapshotname", &snapshotname) < 0) { if (vshCommandOptStringReq(ctl, cmd, "snapshotname", &snapshotname) < 0)
vshError(ctl, _("invalid snapshotname argument '%s'"), snapshotname);
goto cleanup; goto cleanup;
}
if (snapshotname) { if (snapshotname) {
virDomainSnapshotPtr snapshot2 = NULL; virDomainSnapshotPtr snapshot2 = NULL;
flags = (VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE | flags = (VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册