]> git.0d.be Git - empathy.git/commitdiff
[empathy_builder_get_file] NULL out passed GObj ptrs if GtkBuilder file broken
authorDavyd Madeley <davyd@madeley.id.au>
Tue, 1 Sep 2009 04:11:47 +0000 (14:11 +1000)
committerDavyd Madeley <davyd@madeley.id.au>
Tue, 1 Sep 2009 04:11:47 +0000 (14:11 +1000)
If the GtkBuilder file passed to empathy_builder_get_file is broken, it
returns NULL, but doesn't touch the contents of any pointers passed to retrieve
GObjects. In several places we start using these pointers without checking
whether the file was actually setup, which causes Empathy to crash.

Ideally callers of empathy_builder_get_file() should check whether or not
the function returned correctly before using any of the passed pointers, but
in case they don't, make sure we're not passing pointers to random memory.

libempathy-gtk/empathy-ui-utils.c

index 3089c46eae091927fd1251846253e287671d2123..1b02195d2db4c498a071645f52950c1f97786c66 100644 (file)
@@ -99,9 +99,19 @@ builder_get_file_valist (const gchar *filename,
 
        gui = gtk_builder_new ();
        if (!gtk_builder_add_from_file (gui, filename, &error)) {
-               g_critical ("GtkBuilder Error: %s", error->message);
+               g_critical ("GtkBuilder Error (%s): %s",
+                               filename, error->message);
                g_clear_error (&error);
                g_object_unref (gui);
+
+               /* we need to iterate and set all of the pointers to NULL */
+               for (name = first_object; name;
+                    name = va_arg (args, const gchar *)) {
+                       object_ptr = va_arg (args, GObject**);
+
+                       *object_ptr = NULL;
+               }
+
                return NULL;
        }