提交 2e2a81be 编写于 作者: E Eric Blake 提交者: Cole Robinson

snapshot: avoid virsh crash with older servers

Commits 51082301, 16d7b390, 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.
(cherry picked from commit d9f60665)
上级 a52a99f5
...@@ -16482,10 +16482,10 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) ...@@ -16482,10 +16482,10 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
qsort(&names[0], actual, sizeof(char*), namesorter); qsort(&names[0], actual, sizeof(char*), namesorter);
if (tree || ctl->useSnapshotOld) { if (tree || (from && ctl->useSnapshotOld)) {
parents = vshCalloc(ctl, sizeof(char *), actual); parents = vshCalloc(ctl, sizeof(char *), actual);
for (i = (from && !ctl->useSnapshotOld); i < actual; i++) { 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; start_index = i;
continue; continue;
} }
...@@ -16507,7 +16507,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) ...@@ -16507,7 +16507,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
char indentBuf[INDENT_BUFLEN]; char indentBuf[INDENT_BUFLEN];
for (i = 0 ; i < actual ; i++) { for (i = 0 ; i < actual ; i++) {
memset(indentBuf, '\0', sizeof(indentBuf)); 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, cmdNodeListDevicesPrint(ctl,
names, names,
parents, parents,
...@@ -16576,7 +16577,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) ...@@ -16576,7 +16577,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
} }
for (i = 0; i < actual; i++) { for (i = 0; i < actual; i++) {
if (ctl->useSnapshotOld && if (from && ctl->useSnapshotOld &&
(descendants ? !names[i] : STRNEQ_NULLABLE(parents[i], from))) (descendants ? !names[i] : STRNEQ_NULLABLE(parents[i], from)))
continue; continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册