render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
0a7476
From 7fcdf3bbd65b4f3e21128089a559c064edbcb8dc Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <7fcdf3bbd65b4f3e21128089a559c064edbcb8dc@dist-git>
0a7476
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
0a7476
Date: Tue, 21 May 2019 11:02:12 +0100
0a7476
Subject: [PATCH] util: require command args to be non-NULL
0a7476
MIME-Version: 1.0
0a7476
Content-Type: text/plain; charset=UTF-8
0a7476
Content-Transfer-Encoding: 8bit
0a7476
0a7476
The virCommand APIs do not expect to be given a NULL value for an arg
0a7476
name or value. Such a mistake can lead to execution of the wrong
0a7476
command, as the NULL may prematurely terminate the list of args.
0a7476
Detect this and report suitable error messages.
0a7476
0a7476
This identified a flaw in the storage test which was passing a NULL
0a7476
instead of the volume path. This flaw was then validated by an incorrect
0a7476
set of qemu-img args as expected data.
0a7476
0a7476
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
0a7476
(cherry picked from commit 912c6b22fc622cd7c7d29c7f8eaeb816b266daac)
0a7476
0a7476
https: //bugzilla.redhat.com/show_bug.cgi?id=1672957
0a7476
Message-Id: <20190521100213.16875-2-berrange@redhat.com>
0a7476
Reviewed-by: Ján Tomko <jtomko@redhat.com>
0a7476
---
0a7476
 src/util/vircommand.c                                | 10 ++++++++++
0a7476
 tests/storagevolxml2argvdata/qcow2-zerocapacity.argv |  2 +-
0a7476
 tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml |  1 +
0a7476
 3 files changed, 12 insertions(+), 1 deletion(-)
0a7476
0a7476
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
0a7476
index 6dab105f56..68cf63c28a 100644
0a7476
--- a/src/util/vircommand.c
0a7476
+++ b/src/util/vircommand.c
0a7476
@@ -1509,6 +1509,12 @@ virCommandAddArg(virCommandPtr cmd, const char *val)
0a7476
     if (!cmd || cmd->has_error)
0a7476
         return;
0a7476
 
0a7476
+    if (val == NULL) {
0a7476
+        cmd->has_error = EINVAL;
0a7476
+        abort();
0a7476
+        return;
0a7476
+    }
0a7476
+
0a7476
     if (VIR_STRDUP_QUIET(arg, val) < 0) {
0a7476
         cmd->has_error = ENOMEM;
0a7476
         return;
0a7476
@@ -1606,6 +1612,10 @@ virCommandAddArgFormat(virCommandPtr cmd, const char *format, ...)
0a7476
 void
0a7476
 virCommandAddArgPair(virCommandPtr cmd, const char *name, const char *val)
0a7476
 {
0a7476
+    if (name == NULL || val == NULL) {
0a7476
+        cmd->has_error = EINVAL;
0a7476
+        return;
0a7476
+    }
0a7476
     virCommandAddArgFormat(cmd, "%s=%s", name, val);
0a7476
 }
0a7476
 
0a7476
diff --git a/tests/storagevolxml2argvdata/qcow2-zerocapacity.argv b/tests/storagevolxml2argvdata/qcow2-zerocapacity.argv
0a7476
index d83b08b342..45894931ae 100644
0a7476
--- a/tests/storagevolxml2argvdata/qcow2-zerocapacity.argv
0a7476
+++ b/tests/storagevolxml2argvdata/qcow2-zerocapacity.argv
0a7476
@@ -1 +1 @@
0a7476
-qemu-img create -f qcow2 -o compat=0.10  0K
0a7476
+qemu-img create -f qcow2 -o compat=0.10 /var/lib/libvirt/images/OtherDemo.img 0K
0a7476
diff --git a/tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml b/tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml
0a7476
index 1d1e6deac0..027a73b4bf 100644
0a7476
--- a/tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml
0a7476
+++ b/tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml
0a7476
@@ -1,6 +1,7 @@
0a7476
 <volume>
0a7476
   <name>OtherDemo.img</name>
0a7476
   <target>
0a7476
+    <path>/var/lib/libvirt/images/OtherDemo.img</path>
0a7476
     <format type="qcow2"/>
0a7476
   </target>
0a7476
   <capacity>0</capacity>
0a7476
-- 
0a7476
2.21.0
0a7476