From nobody Mon Feb 9 15:45:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1654154357; cv=none; d=zohomail.com; s=zohoarc; b=Ld9tu4WUnDfaxjV6yY27jpwyhV8EtDXBrL//MRlhcNAIRt5d+Ou/SPlgoRHrJCIvx72BP+PZYXzjfKt9LiiG7waZDC7grUHX8/Q/IhmSbSj5nWFr5FEjYPpYZmLho7KTjoC21Z8NtZGmO9l85g0GL5UtmRchvUUoxIAgrj6u5ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654154357; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EmLdOgDGyeSW8MS7smRUpU6LAuWMCACgnhueA4+u0a8=; b=GtFcURQbbC4xj72PY5MJXxhP0O3m08lWFzf9SV1SnCAghJEcbe8NDdcuE7OsLplXw/ZicG2FrHmCo2N6I6i7oeYDaEbA4eglLCUT1Xj3QyabeVvyD6t4Ln5N4SxUw/v8i7CcmxH+lkhdOIksDXHXcq59JzWBe6lkvvkbnnZ9/bs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1654154357195793.8058132149421; Thu, 2 Jun 2022 00:19:17 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-34-VfAboSlINwy_Q7onlI_rTg-1; Thu, 02 Jun 2022 03:18:23 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A18E185A7B2; Thu, 2 Jun 2022 07:18:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17620492C3B; Thu, 2 Jun 2022 07:18:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D60531947B87; Thu, 2 Jun 2022 07:18:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A04451947B87 for ; Thu, 2 Jun 2022 07:18:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8D68F2166B2C; Thu, 2 Jun 2022 07:18:12 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3360A2166B26 for ; Thu, 2 Jun 2022 07:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654154356; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EmLdOgDGyeSW8MS7smRUpU6LAuWMCACgnhueA4+u0a8=; b=MKW1FwohRlzy1Ug+gpcqfasozOQfTPv7//oFjRmBthSmdgr3zNfq9z8MaXpbvLhEv5ZNdb qg0j78otPx3XaAMG4RjJb30B0/1kDDZaY98wfFr+R0u6AXpDSmVLocmenjkIDI/BS0oCHn HFEgD05qxpkU9at6iDyiEKhKVIipi0g= X-MC-Unique: VfAboSlINwy_Q7onlI_rTg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 01/16] virml: Introduce VIR_XML_PROP_NONNEGATIVE flag Date: Thu, 2 Jun 2022 09:17:51 +0200 Message-Id: <2c84145b8caa70e666181252ec80628a74a672e2.1654154053.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1654154358931100001 Content-Type: text/plain; charset="utf-8"; x-default="true" For easier attribute parsing we have virXMLProp*() family of functions. These accept flags through which a caller can pose some conditions onto the attribute value, for instance: VIR_XML_PROP_NONZERO when the attribute may not be zero, etc. What we are missing is VIR_XML_PROP_NONNEGATIVE when the attribute value may be non-negative. Obviously, this flag makes sense only for some members of the virXMLProp*() family. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/util/virxml.c | 7 +++++++ src/util/virxml.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 12b2ef635a..d6e2e5dd91 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -643,6 +643,13 @@ virXMLPropInt(xmlNodePtr node, return -1; } =20 + if ((flags & VIR_XML_PROP_NONNEGATIVE) && (val < 0)) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected non-negative value"), + name, node->name, tmp); + return -1; + } + if ((flags & VIR_XML_PROP_NONZERO) && (val =3D=3D 0)) { virReportError(VIR_ERR_XML_ERROR, _("Invalid value for attribute '%s' in element '%s'= : Zero is not permitted"), diff --git a/src/util/virxml.h b/src/util/virxml.h index 5d49056bc7..539228a9ba 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -38,6 +38,9 @@ typedef enum { VIR_XML_PROP_NONE =3D 0, VIR_XML_PROP_REQUIRED =3D 1 << 0, /* Attribute may not be absent */ VIR_XML_PROP_NONZERO =3D 1 << 1, /* Attribute may not be zero */ + VIR_XML_PROP_NONNEGATIVE =3D 1 << 2, /* Attribute may not be negative,= makes + sense only for some virXMLProp*() + functions. */ } virXMLPropFlags; =20 =20 --=20 2.35.1