Re: [libvirt] [libvirt-glib/libvirt-gconfig 17/17] gconfig, graphics: Avoid crash when gvir_config_object_new_from_xml() returns NULL

2016-09-06 Thread Christophe Fergeau
On Thu, Apr 21, 2016 at 01:05:45PM +0200, Christophe Fergeau wrote:
> This issues is more widespread than that, it would be better to fix it
> everywhere in one go (maybe through a gvir_config_object_check_type() or
> something like this?)

I believe this patch should do for now (with runtime warnings). Since
I'm not sure how widespread _new_from_xml() use is, maybe it's enough
for now, and we can decide on the best way to handle a NULL return when
we start getting runtime warnings from that patch?


From 0b428df2d82b6e669b50a3c400716c3883f9fe9c Mon Sep 17 00:00:00 2001
From: Christophe Fergeau 
Date: Tue, 6 Sep 2016 10:30:58 +0200
Subject: [libvirt-glib] gconfig: Add precondition to
 gvir_config_object_get_xml_node()

This will catch (among other things) cases when
gvir_config_object_get_xml_node() is called with a NULL argument. Not
catching this could cause a crash later on in cases when
gvir_config_object_new_from_xml() is called and returns NULL, and then
we call gvir_config_object_get_attribute() on it.
Now this should be caught with runtime warnings so that the underlying
issue can be fixed.
---
 libvirt-gconfig/libvirt-gconfig-object.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libvirt-gconfig/libvirt-gconfig-object.c 
b/libvirt-gconfig/libvirt-gconfig-object.c
index 6225de2..8cc4065 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -284,6 +284,8 @@ gvir_config_object_get_xml_doc(GVirConfigObject *config)
 G_GNUC_INTERNAL xmlNodePtr
 gvir_config_object_get_xml_node(GVirConfigObject *config)
 {
+g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(config), NULL);
+
 return config->priv->node;
 }
 
-- 
2.7.4


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [libvirt-glib/libvirt-gconfig 17/17] gconfig, graphics: Avoid crash when gvir_config_object_new_from_xml() returns NULL

2016-04-21 Thread Christophe Fergeau
This issues is more widespread than that, it would be better to fix it
everywhere in one go (maybe through a gvir_config_object_check_type() or
something like this?)

Christophe

On Tue, Mar 22, 2016 at 11:04:53AM +0100, Fabiano Fidêncio wrote:
> Signed-off-by: Fabiano Fidêncio 
> ---
>  libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c | 3 +++
>  libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c | 3 +++
>  libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c | 3 +++
>  libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c   | 3 +++
>  libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c | 3 +++
>  5 files changed, 15 insertions(+)
> 
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c 
> b/libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c
> index 7d23b77..092020d 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c
> @@ -66,6 +66,9 @@ gvir_config_domain_graphics_desktop_new_from_xml(const 
> gchar *xml,
>  
>  object = 
> gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_DESKTOP,
>   "graphics", NULL, xml, error);
> +if (object == NULL)
> +return NULL;
> +
>  if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
> "desktop") != 0) {
>  g_object_unref(G_OBJECT(object));
>  return NULL;
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c 
> b/libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c
> index 4671b13..024c7e9 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c
> @@ -66,6 +66,9 @@ gvir_config_domain_graphics_rdp_new_from_xml(const gchar 
> *xml,
>  
>  object = 
> gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_RDP,
>   "graphics", NULL, xml, error);
> +if (object == NULL)
> +return NULL;
> +
>  if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
> "rdp") != 0) {
>  g_object_unref(G_OBJECT(object));
>  return NULL;
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c 
> b/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c
> index 55d0012..3bb6c98 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c
> @@ -66,6 +66,9 @@ gvir_config_domain_graphics_sdl_new_from_xml(const gchar 
> *xml,
>  
>  object = 
> gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SDL,
>   "graphics", NULL, xml, error);
> +if (object == NULL)
> +return NULL;
> +
>  if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
> "sdl") != 0) {
>  g_object_unref(G_OBJECT(object));
>  return NULL;
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c 
> b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
> index 74466d0..9951ab6 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
> @@ -67,6 +67,9 @@ gvir_config_domain_graphics_spice_new_from_xml(const gchar 
> *xml,
>  
>  object = 
> gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SPICE,
>   "graphics", NULL, xml, error);
> +if (object == NULL)
> +return NULL;
> +
>  if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
> "spice") != 0) {
>  g_object_unref(G_OBJECT(object));
>  return NULL;
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c 
> b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c
> index 4bd7b25..1cccb31 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c
> @@ -66,6 +66,9 @@ gvir_config_domain_graphics_vnc_new_from_xml(const gchar 
> *xml,
>  
>  object = 
> gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_VNC,
>   "graphics", NULL, xml, error);
> +if (object == NULL)
> +return NULL;
> +
>  if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
> "vnc") != 0) {
>  g_object_unref(G_OBJECT(object));
>  return NULL;
> -- 
> 2.5.0
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [libvirt-glib/libvirt-gconfig 17/17] gconfig, graphics: Avoid crash when gvir_config_object_new_from_xml() returns NULL

2016-03-22 Thread Fabiano Fidêncio
Signed-off-by: Fabiano Fidêncio 
---
 libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c | 3 +++
 libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c | 3 +++
 libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c | 3 +++
 libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c   | 3 +++
 libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c | 3 +++
 5 files changed, 15 insertions(+)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c 
b/libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c
index 7d23b77..092020d 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c
@@ -66,6 +66,9 @@ gvir_config_domain_graphics_desktop_new_from_xml(const gchar 
*xml,
 
 object = 
gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_DESKTOP,
  "graphics", NULL, xml, error);
+if (object == NULL)
+return NULL;
+
 if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
"desktop") != 0) {
 g_object_unref(G_OBJECT(object));
 return NULL;
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c 
b/libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c
index 4671b13..024c7e9 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c
@@ -66,6 +66,9 @@ gvir_config_domain_graphics_rdp_new_from_xml(const gchar *xml,
 
 object = 
gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_RDP,
  "graphics", NULL, xml, error);
+if (object == NULL)
+return NULL;
+
 if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
"rdp") != 0) {
 g_object_unref(G_OBJECT(object));
 return NULL;
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c 
b/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c
index 55d0012..3bb6c98 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c
@@ -66,6 +66,9 @@ gvir_config_domain_graphics_sdl_new_from_xml(const gchar *xml,
 
 object = 
gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SDL,
  "graphics", NULL, xml, error);
+if (object == NULL)
+return NULL;
+
 if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
"sdl") != 0) {
 g_object_unref(G_OBJECT(object));
 return NULL;
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c 
b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
index 74466d0..9951ab6 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
@@ -67,6 +67,9 @@ gvir_config_domain_graphics_spice_new_from_xml(const gchar 
*xml,
 
 object = 
gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SPICE,
  "graphics", NULL, xml, error);
+if (object == NULL)
+return NULL;
+
 if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
"spice") != 0) {
 g_object_unref(G_OBJECT(object));
 return NULL;
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c 
b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c
index 4bd7b25..1cccb31 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c
@@ -66,6 +66,9 @@ gvir_config_domain_graphics_vnc_new_from_xml(const gchar *xml,
 
 object = 
gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_VNC,
  "graphics", NULL, xml, error);
+if (object == NULL)
+return NULL;
+
 if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), 
"vnc") != 0) {
 g_object_unref(G_OBJECT(object));
 return NULL;
-- 
2.5.0

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