From nobody Mon Apr 29 03:20:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1545052844120293.50716091219545; Mon, 17 Dec 2018 05:20:44 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A120081F13; Mon, 17 Dec 2018 13:20:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45D2018ED7; Mon, 17 Dec 2018 13:20:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 96EB9181B9E9; Mon, 17 Dec 2018 13:20:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wBHDKXOM024732 for ; Mon, 17 Dec 2018 08:20:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 46CF1105959E; Mon, 17 Dec 2018 13:20:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-62.ams2.redhat.com [10.36.112.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D11610595A6; Mon, 17 Dec 2018 13:20:28 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 17 Dec 2018 13:20:26 +0000 Message-Id: <20181217132026.5451-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: require command args to be non-NULL X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 17 Dec 2018 13:20:42 +0000 (UTC) The virCommand APIs do not expect to be given a NULL value for an arg name or value. Such a mistake can lead to execution of the wrong command, as the NULL may prematurely terminate the list of args. Detect this and report suitable error messages. This identified a flaw in the storage test which was passing a NULL instead of the volume path. This flaw was then validated by an incorrect set of qemu-img args as expected data. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/vircommand.c | 10 ++++++++++ tests/storagevolxml2argvdata/qcow2-zerocapacity.argv | 2 +- tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 3559f4bafa..d965068369 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1498,6 +1498,12 @@ virCommandAddArg(virCommandPtr cmd, const char *val) if (!cmd || cmd->has_error) return; =20 + if (val =3D=3D NULL) { + cmd->has_error =3D EINVAL; + abort(); + return; + } + if (VIR_STRDUP_QUIET(arg, val) < 0) { cmd->has_error =3D ENOMEM; return; @@ -1595,6 +1601,10 @@ virCommandAddArgFormat(virCommandPtr cmd, const char= *format, ...) void virCommandAddArgPair(virCommandPtr cmd, const char *name, const char *val) { + if (name =3D=3D NULL || val =3D=3D NULL) { + cmd->has_error =3D EINVAL; + return; + } virCommandAddArgFormat(cmd, "%s=3D%s", name, val); } =20 diff --git a/tests/storagevolxml2argvdata/qcow2-zerocapacity.argv b/tests/s= toragevolxml2argvdata/qcow2-zerocapacity.argv index d83b08b342..45894931ae 100644 --- a/tests/storagevolxml2argvdata/qcow2-zerocapacity.argv +++ b/tests/storagevolxml2argvdata/qcow2-zerocapacity.argv @@ -1 +1 @@ -qemu-img create -f qcow2 -o compat=3D0.10 0K +qemu-img create -f qcow2 -o compat=3D0.10 /var/lib/libvirt/images/OtherDem= o.img 0K diff --git a/tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml b/tests/s= toragevolxml2xmlin/vol-qcow2-zerocapacity.xml index 1d1e6deac0..027a73b4bf 100644 --- a/tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml +++ b/tests/storagevolxml2xmlin/vol-qcow2-zerocapacity.xml @@ -1,6 +1,7 @@ OtherDemo.img + /var/lib/libvirt/images/OtherDemo.img 0 --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list