[libvirt PATCH v2 6/6] virDomainAudioSDLParse: Use virXMLProp*

Tim Wiederhake posted 6 patches 4 years, 9 months ago
There is a newer version of this series
[libvirt PATCH v2 6/6] virDomainAudioSDLParse: Use virXMLProp*
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 `bufferCount`.

`bufferCount` does not benefit from being referable as e.g. "-7" for
requesting 4294967289 buffers, as this value is distinctly out of range
for normal use.

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

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 145b898adb..66217289d1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13455,15 +13455,9 @@ static int
 virDomainAudioSDLParse(virDomainAudioIOSDL *def,
                        xmlNodePtr node)
 {
-    g_autofree char *bufferCount = virXMLPropString(node, "bufferCount");
-
-    if (bufferCount &&
-        virStrToLong_ui(bufferCount, NULL, 10,
-                        &def->bufferCount) < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("cannot parse 'bufferCount' value '%s'"), bufferCount);
+    if (virXMLPropUInt(node, "bufferCount", 10, VIR_XML_PROP_NONE,
+                       &def->bufferCount) < 0)
         return -1;
-    }
 
     return 0;
 }
-- 
2.26.3

Re: [libvirt PATCH v2 6/6] virDomainAudioSDLParse: Use virXMLProp*
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 `bufferCount`.
>
>`bufferCount` does not benefit from being referable as e.g. "-7" for
>requesting 4294967289 buffers, as this value is distinctly out of range
>for normal use.
>
>Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
>---
> src/conf/domain_conf.c | 10 ++--------
> 1 file changed, 2 insertions(+), 8 deletions(-)
>

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

Jano