From nobody Sat Feb 7 04:40:42 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=1654696034; cv=none; d=zohomail.com; s=zohoarc; b=ODnq4R4Dm5q/or5E8qxZzsxNGiCgnxsYVj9D0vDCxX9SqEFPDS6PTWQk1uz+wqLCq4O6GXVOwJwcFsuWmLcjzdUCWHSoF9Hu2MW3HRGCK966RJVPwNu9iC7DpAZ5iILANRfS8tiXpakWnrLzq6oZMUStOdQw5w4HdNEtvv1OkKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654696034; 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=cqpzclSCWbb6ihm48TtQXDr/wA3t4ZUX+BFMa3J1EHA=; b=BU+hCAu4/gb9Btn9RooOY0dTcLi18NF8nyrhser19s/a+J18cKsh8IkMv0tqOaA3MCVO6UC1JklI9N1EE8i0vNLOnrwz3y+CLQcSK3Jiy7AAPbO1Fmp76dtwkAT+uvSucCkMrFW+nPLzxWPcJ5Iz73rz4WakwyRikr+TWK6SyWA= 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 1654696034462138.75530545266383; Wed, 8 Jun 2022 06:47:14 -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-93-qEeu1FczO2ue9NwWsl4wyg-1; Wed, 08 Jun 2022 09:47:10 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8334101E986; Wed, 8 Jun 2022 13:47:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D4AC1415100; Wed, 8 Jun 2022 13:47:07 +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 583491947041; Wed, 8 Jun 2022 13:47:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BF66D1947040 for ; Wed, 8 Jun 2022 13:43:11 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A0F2D492CA3; Wed, 8 Jun 2022 13:43:11 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48D6A492C3B for ; Wed, 8 Jun 2022 13:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654696033; 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=cqpzclSCWbb6ihm48TtQXDr/wA3t4ZUX+BFMa3J1EHA=; b=VwbdahkJXg1onX/RtWa4rjXCfzsIRBlSR+mHuTOD36PLU+CkYkMTrvJtZXpOUpoqqjXmMt YQlVk3nT4A7QpYamIXXHoo6kifZIGEjSfC+GecMh0+iKxmnuexqE7EeATpk3vE+KaF2kCq qCUcqhyrlMyarsD9I5EJaTpzFSxtZSc= X-MC-Unique: qEeu1FczO2ue9NwWsl4wyg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 01/15] virml: Introduce VIR_XML_PROP_NONNEGATIVE flag Date: Wed, 8 Jun 2022 15:42:55 +0200 Message-Id: <9ee48bb0cdf404f682bdf13fc843b90cc74acb98.1654695585.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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.7 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: 1654696035031100001 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