[libvirt PATCH v2 3/6] virDomainFeaturesDefParse: Use virXMLPropUInt

Tim Wiederhake posted 6 patches 4 years, 9 months ago
There is a newer version of this series
[libvirt PATCH v2 3/6] virDomainFeaturesDefParse: Use virXMLPropUInt
Posted by Tim Wiederhake 4 years, 9 months ago
This strictens the parser to disallow negative values (interpreted as
`UINT_MAX + value + 1`) for attribute `retries`. UINT_MAX holds no
special significance for this attribute and is distinctly out of range
for normal use.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
---
 src/conf/domain_conf.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 59630415a4..b1e5115c7e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18108,12 +18108,10 @@ virDomainFeaturesDefParse(virDomainDef *def,
                 if (value != VIR_TRISTATE_SWITCH_ON)
                     break;
 
-                if (virXPathUInt("string(./@retries)", ctxt,
-                             &def->hyperv_spinlocks) < 0) {
-                    virReportError(VIR_ERR_XML_ERROR, "%s",
-                                   _("invalid HyperV spinlock retry count"));
+                if (virXMLPropUInt(nodes[i], "retries", 0,
+                                   VIR_XML_PROP_REQUIRED,
+                                   &def->hyperv_spinlocks) < 0)
                     return -1;
-                }
 
                 if (def->hyperv_spinlocks < 0xFFF) {
                     virReportError(VIR_ERR_XML_ERROR, "%s",
-- 
2.26.3

Re: [libvirt PATCH v2 3/6] virDomainFeaturesDefParse: Use virXMLPropUInt
Posted by Ján Tomko 4 years, 9 months ago
On a Tuesday in 2021, Tim Wiederhake wrote:
>This strictens the parser to disallow negative values (interpreted as
>`UINT_MAX + value + 1`) for attribute `retries`. UINT_MAX holds no
>special significance for this attribute and is distinctly out of range
>for normal use.
>
>Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
>---
> src/conf/domain_conf.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano