提交 72437526 编写于 作者: E Eric Blake

virsh: don't crash if shutdown --mode not provided

virStringSplit requires a non-NULL input, but commit cef78ed8 forgot
to follow the rule.

* tools/virsh-domain.c (cmdReboot, cmdShutdown): Avoid NULL deref.
上级 5a608c3d
...@@ -4036,20 +4036,20 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) ...@@ -4036,20 +4036,20 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
const char *mode = NULL; const char *mode = NULL;
int flags = 0; int flags = 0;
int rv; int rv;
char **modes, **tmp; char **modes = NULL, **tmp;
if (vshCommandOptString(cmd, "mode", &mode) < 0) { if (vshCommandOptString(cmd, "mode", &mode) < 0) {
vshError(ctl, "%s", _("Invalid type")); vshError(ctl, "%s", _("Invalid type"));
return false; return false;
} }
if (!(modes = virStringSplit(mode, ",", 0))) { if (mode && !(modes = virStringSplit(mode, ",", 0))) {
vshError(ctl, "%s", _("Cannot parse mode string")); vshError(ctl, "%s", _("Cannot parse mode string"));
return false; return false;
} }
tmp = modes; tmp = modes;
while (*tmp) { while (tmp && *tmp) {
mode = *tmp; mode = *tmp;
if (STREQ(mode, "acpi")) { if (STREQ(mode, "acpi")) {
flags |= VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN; flags |= VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN;
...@@ -4112,20 +4112,20 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) ...@@ -4112,20 +4112,20 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
const char *name; const char *name;
const char *mode = NULL; const char *mode = NULL;
int flags = 0; int flags = 0;
char **modes, **tmp; char **modes = NULL, **tmp;
if (vshCommandOptString(cmd, "mode", &mode) < 0) { if (vshCommandOptString(cmd, "mode", &mode) < 0) {
vshError(ctl, "%s", _("Invalid type")); vshError(ctl, "%s", _("Invalid type"));
return false; return false;
} }
if (!(modes = virStringSplit(mode, ",", 0))) { if (mode && !(modes = virStringSplit(mode, ",", 0))) {
vshError(ctl, "%s", _("Cannot parse mode string")); vshError(ctl, "%s", _("Cannot parse mode string"));
return false; return false;
} }
tmp = modes; tmp = modes;
while (*tmp) { while (tmp && *tmp) {
mode = *tmp; mode = *tmp;
if (STREQ(mode, "acpi")) { if (STREQ(mode, "acpi")) {
flags |= VIR_DOMAIN_REBOOT_ACPI_POWER_BTN; flags |= VIR_DOMAIN_REBOOT_ACPI_POWER_BTN;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册