]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
snapshot: avoid virsh crash with older servers
authorEric Blake <eblake@redhat.com>
Fri, 8 Jun 2012 03:46:47 +0000 (21:46 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 11 Jun 2012 14:22:03 +0000 (08:22 -0600)
Commits 5108230116d7b39, and 521cc447 introduced support for
'virsh snapshot-list --from' when talking to a server older than
0.9.5, but broke support for plain 'virsh snapshot-list' for the
same old server in the process.  Because the code is not properly
gated, we end up with a SIGSEGV during a strcmp with a NULL argument.

* tools/virsh.c (cmdSnapshotList): Don't waste time on fallbacks
when --from is not present.

tools/virsh.c

index abcfbffa388d36bdc56049abf7cf9aeaabdda4a7..0453b954effa9c32060e63451a97fef70c84a5c6 100644 (file)
@@ -16740,10 +16740,10 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
 
     qsort(&names[0], actual, sizeof(char*), namesorter);
 
-    if (tree || ctl->useSnapshotOld) {
+    if (tree || (from && ctl->useSnapshotOld)) {
         parents = vshCalloc(ctl, sizeof(char *), actual);
         for (i = (from && !ctl->useSnapshotOld); i < actual; i++) {
-            if (ctl->useSnapshotOld && STREQ(names[i], from)) {
+            if (from && ctl->useSnapshotOld && STREQ(names[i], from)) {
                 start_index = i;
                 continue;
             }
@@ -16765,7 +16765,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
         char indentBuf[INDENT_BUFLEN];
         for (i = 0 ; i < actual ; i++) {
             memset(indentBuf, '\0', sizeof(indentBuf));
-            if (ctl->useSnapshotOld ? STREQ(names[i], from) : !parents[i])
+            if ((from && ctl->useSnapshotOld) ? STREQ(names[i], from) :
+                !parents[i])
                 cmdNodeListDevicesPrint(ctl,
                                         names,
                                         parents,
@@ -16834,7 +16835,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
         }
 
         for (i = 0; i < actual; i++) {
-            if (ctl->useSnapshotOld &&
+            if (from && ctl->useSnapshotOld &&
                 (descendants ? !names[i] : STRNEQ_NULLABLE(parents[i], from)))
                 continue;