[libvirt PATCH 10/10] virDomainAudioSDLParse: Use virXMLProp*

Tim Wiederhake posted 10 patches 1 month, 3 weeks ago

[libvirt PATCH 10/10] virDomainAudioSDLParse: Use virXMLProp*

Posted by Tim Wiederhake 1 month, 3 weeks ago
This strictens the parser to disallow negative values (interpreted as
`UINT_MAX + value + 1`) for attribute `bufferCount`.

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 bff17057af..12bdc12f54 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 10/10] virDomainAudioSDLParse: Use virXMLProp*

Posted by Daniel P. Berrangé 1 month, 3 weeks ago
On Fri, Apr 23, 2021 at 05:39:23PM +0200, Tim Wiederhake wrote:
> This strictens the parser to disallow negative values (interpreted as
> `UINT_MAX + value + 1`) for attribute `bufferCount`.

I don't get what's different here - we were already using
virStrToLong_ui to get positive values.

> 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 bff17057af..12bdc12f54 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;
>  }

Why is this only modifying parsing of this one attribute for the
SDL audio backend, and not the other identical code patterns for
other audi backends

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Re: [libvirt PATCH 10/10] virDomainAudioSDLParse: Use virXMLProp*

Posted by Peter Krempa 1 month, 3 weeks ago
On Mon, Apr 26, 2021 at 12:48:47 +0100, Daniel P. Berrangé wrote:
> On Fri, Apr 23, 2021 at 05:39:23PM +0200, Tim Wiederhake wrote:
> > This strictens the parser to disallow negative values (interpreted as
> > `UINT_MAX + value + 1`) for attribute `bufferCount`.
> 
> I don't get what's different here - we were already using
> virStrToLong_ui to get positive values.

virStrToLong_ui accepts -1 as valid input and wraps around to the max
value. virStrToLong_uip is a version that doesn't have this weird
behaviour.

We actually document and rely on the wraparound in certain cases as
shortcuts for MAX value, thus any change from _ui to _uip equivalent
must be properly justified as not making sense/not being documented.