rygel,ui: Stop crashing because of non-null terminated arrays
authorJens Georg <jensg@openismus.com>
Fri, 10 May 2013 18:56:15 +0000 (20:56 +0200)
committerJens Georg <jensg@openismus.com>
Fri, 10 May 2013 18:56:15 +0000 (20:56 +0200)
src/rygel/rygel-user-config.vala
src/ui/rygel-network-pref-section.vala

index 83c6dc0..532c19b 100644 (file)
@@ -155,7 +155,14 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
 
     [CCode (array_length=false, array_null_terminated = true)]
     public string[] get_interfaces () throws GLib.Error {
-        return this.get_string_list (GENERAL_SECTION, IFACE_KEY).to_array ();
+        var interfaces = this.get_string_list (GENERAL_SECTION,
+                                               IFACE_KEY).to_array ();
+        // to_array () is not null-terminated
+        if (interfaces != null) {
+            interfaces += null;
+        }
+
+        return interfaces;
     }
 
     public string get_interface () throws GLib.Error {
index a7a1e36..d0b440a 100644 (file)
@@ -40,9 +40,12 @@ public class Rygel.NetworkPrefSection : PreferencesSection {
         this.context_manager = ContextManager.create (0);
 
         try {
-            this.iface_entry.append_text (config.get_interfaces ()[0]);
-            // TODO: Set the current interface to be active.
-            this.iface_entry.set_active (0);
+            var interfaces = config.get_interfaces ();
+            if (interfaces != null) {
+                this.iface_entry.append_text (interfaces[0]);
+                // TODO: Set the current interface to be active.
+                this.iface_entry.set_active (0);
+            }
         } catch (GLib.Error err) {
             // No problem if we fail to read the config, the default values
             // will do just fine. Same goes for rest of the keys.