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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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

Pushing under the build-breaker rule.

 tools/virsh-domain.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 9f1a3d4..f12777c 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -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;
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]