[libvirt] [PATCH] xenconfig: xm: Fix checking for extra in parser

Filip Alac posted 1 patch 5 years, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20180511083348.4074-1-filipalac@gmail.com
Test syntax-check passed
There is a newer version of this series
src/xenconfig/xen_xm.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
[libvirt] [PATCH] xenconfig: xm: Fix checking for extra in parser
Posted by Filip Alac 5 years, 11 months ago
Parser assumed extra was always present when root was specified.
Fixed by handling root and extra separately.

---
 src/xenconfig/xen_xm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c
index 8ef68bbc..4becb40b 100644
--- a/src/xenconfig/xen_xm.c
+++ b/src/xenconfig/xen_xm.c
@@ -91,10 +91,13 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
         if (xenConfigGetString(conf, "root", &root, NULL) < 0)
             return -1;
 
-        if (root) {
+        if (root && extra) {
             if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
                 return -1;
-        } else {
+        } else if (root) {
+            if (virAsprintf(&def->os.cmdline, "root=%s", root) < 0)
+                return -1;
+        } else if (extra) {
             if (VIR_STRDUP(def->os.cmdline, extra) < 0)
                 return -1;
         }
-- 
2.17.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] xenconfig: xm: Fix checking for extra in parser
Posted by Jim Fehlig 5 years, 11 months ago
On 05/11/2018 02:33 AM, Filip Alac wrote:
> Parser assumed extra was always present when root was specified.
> Fixed by handling root and extra separately.

Contributions to libvirt must now assert they are in compliance with the DCO. 
See https://libvirt.org/hacking.html

> 
> ---
>   src/xenconfig/xen_xm.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c
> index 8ef68bbc..4becb40b 100644
> --- a/src/xenconfig/xen_xm.c
> +++ b/src/xenconfig/xen_xm.c
> @@ -91,10 +91,13 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
>           if (xenConfigGetString(conf, "root", &root, NULL) < 0)
>               return -1;
>   
> -        if (root) {
> +        if (root && extra) {
>               if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
>                   return -1;
> -        } else {
> +        } else if (root) {
> +            if (virAsprintf(&def->os.cmdline, "root=%s", root) < 0)
> +                return -1;
> +        } else if (extra) {
>               if (VIR_STRDUP(def->os.cmdline, extra) < 0)
>                   return -1;
>           }

Although at first glance the logic seems a bit clumsy, my alternative attempts 
were no better. Also, similar logic exits in the xl config parser - see 
xenParseCmdline in xen_xl.c.

ACK to the change, but we'll need a 'Signed-off-by:' to push.

Regards,
Jim

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2] xenconfig: xm: Fix checking for extra in parser
Posted by Filip Alac 5 years, 11 months ago
Parser assumed extra was always present when root was specified.
Fixed by handling root and extra separately.

Signed-off-by: Filip Alac <filipalac@gmail.com>
---
 src/xenconfig/xen_xm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c
index 8ef68bbc..4becb40b 100644
--- a/src/xenconfig/xen_xm.c
+++ b/src/xenconfig/xen_xm.c
@@ -91,10 +91,13 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
         if (xenConfigGetString(conf, "root", &root, NULL) < 0)
             return -1;
 
-        if (root) {
+        if (root && extra) {
             if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
                 return -1;
-        } else {
+        } else if (root) {
+            if (virAsprintf(&def->os.cmdline, "root=%s", root) < 0)
+                return -1;
+        } else if (extra) {
             if (VIR_STRDUP(def->os.cmdline, extra) < 0)
                 return -1;
         }
-- 
2.17.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] xenconfig: xm: Fix checking for extra in parser
Posted by Jim Fehlig 5 years, 11 months ago
On 05/12/2018 09:45 AM, Filip Alac wrote:
> Parser assumed extra was always present when root was specified.
> Fixed by handling root and extra separately.
> 
> Signed-off-by: Filip Alac <filipalac@gmail.com>

Reviewed-by: Jim Fehlig <jfehlig@suse.com>

and pushed. Thanks!

Regards,
Jim

> ---
>   src/xenconfig/xen_xm.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c
> index 8ef68bbc..4becb40b 100644
> --- a/src/xenconfig/xen_xm.c
> +++ b/src/xenconfig/xen_xm.c
> @@ -91,10 +91,13 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
>           if (xenConfigGetString(conf, "root", &root, NULL) < 0)
>               return -1;
>   
> -        if (root) {
> +        if (root && extra) {
>               if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
>                   return -1;
> -        } else {
> +        } else if (root) {
> +            if (virAsprintf(&def->os.cmdline, "root=%s", root) < 0)
> +                return -1;
> +        } else if (extra) {
>               if (VIR_STRDUP(def->os.cmdline, extra) < 0)
>                   return -1;
>           }
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] xenconfig: xm: Fix checking for extra in parser
Posted by Cole Robinson 5 years, 11 months ago
On 05/12/2018 11:45 AM, Filip Alac wrote:
> Parser assumed extra was always present when root was specified.
> Fixed by handling root and extra separately.
> 
> Signed-off-by: Filip Alac <filipalac@gmail.com>
> ---
>  src/xenconfig/xen_xm.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c
> index 8ef68bbc..4becb40b 100644
> --- a/src/xenconfig/xen_xm.c
> +++ b/src/xenconfig/xen_xm.c
> @@ -91,10 +91,13 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
>          if (xenConfigGetString(conf, "root", &root, NULL) < 0)
>              return -1;
>  
> -        if (root) {
> +        if (root && extra) {
>              if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
>                  return -1;
> -        } else {
> +        } else if (root) {
> +            if (virAsprintf(&def->os.cmdline, "root=%s", root) < 0)
> +                return -1;
> +        } else if (extra) {
>              if (VIR_STRDUP(def->os.cmdline, extra) < 0)
>                  return -1;
>          }
> 

I'm guessing you came to this issue via
https://bugzilla.redhat.com/show_bug.cgi?id=1327578 . In the future
please add a link to the bug report in the git commit message

Also this is a good candidate for extending the test suite,
tests/xmconfigdata and tests/xmconfigtest.c

Thanks,
Cole

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