]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: don't crash if shutdown --mode not provided
authorEric Blake <eblake@redhat.com>
Fri, 30 Nov 2012 21:48:24 +0000 (14:48 -0700)
committerEric Blake <eblake@redhat.com>
Fri, 30 Nov 2012 21:56:30 +0000 (14:56 -0700)
virStringSplit requires a non-NULL input, but commit cef78ed forgot
to follow the rule.

* tools/virsh-domain.c (cmdReboot, cmdShutdown): Avoid NULL deref.

tools/virsh-domain.c

index 9f1a3d46f1eb96481c1bc34f59906ff606edd61b..f12777c649ac1ac694a695325b2f49ad3e5c6d36 100644 (file)
@@ -4036,20 +4036,20 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
     const char *mode = NULL;
     int flags = 0;
     int rv;
-    char **modes, **tmp;
+    char **modes = NULL, **tmp;
 
     if (vshCommandOptString(cmd, "mode", &mode) < 0) {
         vshError(ctl, "%s", _("Invalid type"));
         return false;
     }
 
-    if (!(modes = virStringSplit(mode, ",", 0))) {
+    if (mode && !(modes = virStringSplit(mode, ",", 0))) {
         vshError(ctl, "%s", _("Cannot parse mode string"));
         return false;
     }
 
     tmp = modes;
-    while (*tmp) {
+    while (tmp && *tmp) {
         mode = *tmp;
         if (STREQ(mode, "acpi")) {
             flags |= VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN;
@@ -4112,20 +4112,20 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
     const char *name;
     const char *mode = NULL;
     int flags = 0;
-    char **modes, **tmp;
+    char **modes = NULL, **tmp;
 
     if (vshCommandOptString(cmd, "mode", &mode) < 0) {
         vshError(ctl, "%s", _("Invalid type"));
         return false;
     }
 
-    if (!(modes = virStringSplit(mode, ",", 0))) {
+    if (mode && !(modes = virStringSplit(mode, ",", 0))) {
         vshError(ctl, "%s", _("Cannot parse mode string"));
         return false;
     }
 
     tmp = modes;
-    while (*tmp) {
+    while (tmp && *tmp) {
         mode = *tmp;
         if (STREQ(mode, "acpi")) {
             flags |= VIR_DOMAIN_REBOOT_ACPI_POWER_BTN;