[libvirt] [PATCH] tests: fix test segfault when libxl configuration setup fails.

Julio Faracco posted 1 patch 5 years, 8 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20180802040639.29731-1-jcfaracco@gmail.com
Test syntax-check passed
tests/libxlxml2domconfigtest.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[libvirt] [PATCH] tests: fix test segfault when libxl configuration setup fails.
Posted by Julio Faracco 5 years, 8 months ago
This commit fixes a segmentation fault caused by missing conditional to
check if libxl configuration was properly created by the test. If the
configuration was not properly created, libxlDriverConfigNew() function
will return NULL and cause a segfault at cfg->caps = NULL during the
cleanup.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
 tests/libxlxml2domconfigtest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
index 34a63e22b5..a9758c40cb 100644
--- a/tests/libxlxml2domconfigtest.c
+++ b/tests/libxlxml2domconfigtest.c
@@ -138,7 +138,8 @@ testCompareXMLToDomConfig(const char *xmlfile,
     libxl_domain_config_dispose(&actualconfig);
     libxl_domain_config_dispose(&expectconfig);
     xtl_logger_destroy(log);
-    cfg->caps = NULL;
+    if (cfg)
+        cfg->caps = NULL;
     virObjectUnref(cfg);
     return ret;
 }
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] tests: fix test segfault when libxl configuration setup fails.
Posted by Erik Skultety 5 years, 8 months ago
On Thu, Aug 02, 2018 at 01:06:39AM -0300, Julio Faracco wrote:
> This commit fixes a segmentation fault caused by missing conditional to
> check if libxl configuration was properly created by the test. If the
> configuration was not properly created, libxlDriverConfigNew() function
> will return NULL and cause a segfault at cfg->caps = NULL during the
> cleanup.
>
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> ---
>  tests/libxlxml2domconfigtest.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
> index 34a63e22b5..a9758c40cb 100644
> --- a/tests/libxlxml2domconfigtest.c
> +++ b/tests/libxlxml2domconfigtest.c
> @@ -138,7 +138,8 @@ testCompareXMLToDomConfig(const char *xmlfile,
>      libxl_domain_config_dispose(&actualconfig);
>      libxl_domain_config_dispose(&expectconfig);
>      xtl_logger_destroy(log);
> -    cfg->caps = NULL;
> +    if (cfg)
> +        cfg->caps = NULL;
>      virObjectUnref(cfg);
>      return ret;

Either this or move the "if (!(cfg - libxlDriverConfigNew()))" before the calls
to the libxl library and return a failure right away, but I don't have a strong
preference here, so

Reviewed-by: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] tests: fix test segfault when libxl configuration setup fails.
Posted by Erik Skultety 5 years, 8 months ago
On Thu, Aug 02, 2018 at 10:35:27AM +0200, Erik Skultety wrote:
> On Thu, Aug 02, 2018 at 01:06:39AM -0300, Julio Faracco wrote:
> > This commit fixes a segmentation fault caused by missing conditional to
> > check if libxl configuration was properly created by the test. If the
> > configuration was not properly created, libxlDriverConfigNew() function
> > will return NULL and cause a segfault at cfg->caps = NULL during the
> > cleanup.
> >
> > Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> > ---
> >  tests/libxlxml2domconfigtest.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
> > index 34a63e22b5..a9758c40cb 100644
> > --- a/tests/libxlxml2domconfigtest.c
> > +++ b/tests/libxlxml2domconfigtest.c
> > @@ -138,7 +138,8 @@ testCompareXMLToDomConfig(const char *xmlfile,
> >      libxl_domain_config_dispose(&actualconfig);
> >      libxl_domain_config_dispose(&expectconfig);
> >      xtl_logger_destroy(log);
> > -    cfg->caps = NULL;
> > +    if (cfg)
> > +        cfg->caps = NULL;
> >      virObjectUnref(cfg);
> >      return ret;
>
> Either this or move the "if (!(cfg - libxlDriverConfigNew()))" before the calls
> to the libxl library and return a failure right away, but I don't have a strong
> preference here, so
>
> Reviewed-by: Erik Skultety <eskultet@redhat.com>

Oh, it's also safe for freeze, so I went ahead and pushed the patch.

Erik

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