On Tue, Mar 12, 2019 at 00:38:06 +0900, Shotaro Gotanda wrote:
> This commit remove redundant common pattern in our XML parsing
> that convert string 'yes' into true and 'no' into false,
> and error if we receive anything other values.
> 
> Signed-off-by: Shotaro Gotanda <g.sho1...@gmail.com>
> ---
>  src/conf/domain_conf.c | 30 +++++-------------------------
>  src/conf/secret_conf.c | 12 ++----------
>  2 files changed, 7 insertions(+), 35 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 995f87bcbe..3830926f3d 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -8412,11 +8412,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
>      p = virXMLPropStringLimit(ctxt->node, "relabel",
>                                VIR_SECURITY_LABEL_BUFLEN-1);
>      if (p) {
> -        if (STREQ(p, "yes")) {
> -            seclabel->relabel = true;
> -        } else if (STREQ(p, "no")) {
> -            seclabel->relabel = false;
> -        } else {
> +        if (virStringParseYesNo(p, &seclabel->relabel) < 0) {

Since virStringParseYesNo reports an error this usage will result in the
error being overwritten. Since the error message here is better as the
one reported in virStringParseYesNo we should keep the original error
handling.

Probably the best solution will be for virStringParseYesNo to avoid
reporting an error and just return -1 in case when the value could not
be converted.

>              virReportError(VIR_ERR_XML_ERROR,
>                             _("invalid security relabel value %s"), p);
>              goto error;

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to