[rygel] rygel, ui: Stop crashing because of non-null terminated arrays



commit 5426f7c9bd9fc064d5e3ad4f3994963032c6c0b7
Author: Jens Georg <jensg openismus com>
Date:   Fri May 10 20:56:15 2013 +0200

    rygel,ui: Stop crashing because of non-null terminated arrays

 src/rygel/rygel-user-config.vala       |    9 ++++++++-
 src/ui/rygel-network-pref-section.vala |    9 ++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index 83c6dc0..532c19b 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -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 {
diff --git a/src/ui/rygel-network-pref-section.vala b/src/ui/rygel-network-pref-section.vala
index a7a1e36..d0b440a 100644
--- a/src/ui/rygel-network-pref-section.vala
+++ b/src/ui/rygel-network-pref-section.vala
@@ -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.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]