[rygel] media-export: Fix potential crasher



commit 147700944c84c7d5abc5b4496726d8e7d9f8d5eb
Author: Jens Georg <jensg openismus com>
Date:   Thu Aug 8 13:31:47 2013 +0200

    media-export: Fix potential crasher
    
    The data passed to the collation function is not null-terminated so we
    make sure it is now. There is no additional copying involved, the code
    was doing g_strdup implicitly anyway before.

 .../media-export/rygel-media-export-collate.c      |   27 ++++++++++++++------
 .../media-export/rygel-media-export-database.vala  |    7 +---
 2 files changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-collate.c 
b/src/plugins/media-export/rygel-media-export-collate.c
index eccf527..aa2553f 100644
--- a/src/plugins/media-export/rygel-media-export-collate.c
+++ b/src/plugins/media-export/rygel-media-export-collate.c
@@ -23,16 +23,27 @@
 #include <glib.h>
 
 #ifdef HAVE_UNISTRING
-#include <unistr.h>
-gint rygel_media_export_utf8_collate_str (const char *a, const char *b)
+#   include <unistr.h>
+#endif
+
+gint rygel_media_export_utf8_collate_str (const char *a, gsize alen,
+                                          const char *b, gsize blen)
 {
-    return u8_strcoll (a, b);
-}
+    char *a_str, *b_str;
+    gint result;
 
+    /* Make sure the passed strings are null terminated */
+    a_str = g_strndup (a, alen);
+    b_str = g_strndup (b, blen);
+
+#ifdef HAVE_UNISTRING
+    result = u8_strcoll (a_str, b_str);
 #else
+    return g_utf8_collate (a_str, b_str);
+#endif
 
-gint rygel_media_export_utf8_collate_str (const char *a, const char *b)
-{
-    return g_utf8_collate (a, b);
+    g_free (a_str);
+    g_free (b_str);
+
+    return result;
 }
-#endif
diff --git a/src/plugins/media-export/rygel-media-export-database.vala 
b/src/plugins/media-export/rygel-media-export-database.vala
index 1b2f3d3..1523337 100644
--- a/src/plugins/media-export/rygel-media-export-database.vala
+++ b/src/plugins/media-export/rygel-media-export-database.vala
@@ -28,7 +28,7 @@ public errordomain Rygel.MediaExport.DatabaseError {
 }
 
 namespace Rygel.MediaExport {
-    extern static int utf8_collate_str (string a, string b);
+    extern static int utf8_collate_str (uint8[] a, uint8[] b);
 }
 
 /**
@@ -74,10 +74,7 @@ internal class Rygel.MediaExport.Database : SqliteWrapper {
         unowned uint8[] _b = (uint8[]) b;
         _b.length = blen;
 
-        var str_a = ((string) _a);
-        var str_b = ((string) _b);
-
-        return utf8_collate_str (str_a, str_b);
+        return utf8_collate_str (_a, _b);
     }
 
     /**


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