[PATCH] virDomainDeviceInfoParseXML: Reject '0' value for ACPI index

Peter Krempa posted 1 patch 2 years, 3 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/c122f8d22bc1c545bdb495c4f744ad62d2db5f6b.1642517511.git.pkrempa@redhat.com
src/conf/domain_conf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] virDomainDeviceInfoParseXML: Reject '0' value for ACPI index
Posted by Peter Krempa 2 years, 3 months ago
Value of '0' is treated equivalently to when it's not provided by the
user. Reject an explicit '0' provided by the user as it would get
ignored.

In this rare case we can make the XML parser more strict, as libvirt
would never format the '<acpi/>' element if the index is '0' thus there
are no libvirt-generated XMLs we'd not load back, as of such this is
identical to rejecting it in the validation phase.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2037146
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/conf/domain_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a805f7f6a3..393f9d9478 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6786,7 +6786,7 @@ virDomainDeviceInfoParseXML(virDomainXMLOption *xmlopt,
     }

     if ((acpi = virXPathNode("./acpi", ctxt))) {
-        if (virXMLPropUInt(acpi, "index", 10, VIR_XML_PROP_NONE,
+        if (virXMLPropUInt(acpi, "index", 10, VIR_XML_PROP_NONZERO,
                            &info->acpiIndex) < 0)
             goto cleanup;
     }
-- 
2.34.1

Re: [PATCH] virDomainDeviceInfoParseXML: Reject '0' value for ACPI index
Posted by Michal Prívozník 2 years, 3 months ago
On 1/18/22 15:51, Peter Krempa wrote:
> Value of '0' is treated equivalently to when it's not provided by the
> user. Reject an explicit '0' provided by the user as it would get
> ignored.
> 
> In this rare case we can make the XML parser more strict, as libvirt
> would never format the '<acpi/>' element if the index is '0' thus there
> are no libvirt-generated XMLs we'd not load back, as of such this is
> identical to rejecting it in the validation phase.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2037146
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/conf/domain_conf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal