render / rpms / libvirt

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