gst/gstregistryxml.c: Make sure we don't pass non-UTF-8 strings to g_markup_escape...
authorTim-Philipp Müller <tim@centricular.net>
Tue, 26 Dec 2006 15:06:52 +0000 (15:06 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Tue, 26 Dec 2006 15:06:52 +0000 (15:06 +0000)
Original commit message from CVS:
* gst/gstregistryxml.c: (gst_registry_save_escaped):
Make sure we don't pass non-UTF-8 strings to g_markup_escape(),
since that can lead to random memory corruptions and crashes
(may or may not be related to #383244, #386711, and #386711).

ChangeLog
gst/gstregistryxml.c

index 201517b..598b6ce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-12-26  Tim-Philipp Müller  <tim at centricular dot net>
+
+       * gst/gstregistryxml.c: (gst_registry_save_escaped):
+         Make sure we don't pass non-UTF-8 strings to g_markup_escape(),
+         since that can lead to random memory corruptions and crashes
+         (may or may not be related to #383244, #386711, and #386711).
+
 2006-12-21  Stefan Kost  <ensonic@users.sf.net>
 
        * tests/check/.cvsignore:
index eebbd8f..8f8e766 100644 (file)
@@ -594,7 +594,14 @@ gst_registry_save_escaped (GstRegistry * registry, char *prefix, char *tag,
   gboolean ret = TRUE;
 
   if (value) {
-    gchar *v = g_markup_escape_text (value, strlen (value));
+    gchar *v;
+
+    if (g_utf8_validate (value, -1, NULL)) {
+      v = g_markup_escape_text (value, -1);
+    } else {
+      g_warning ("Invalid UTF-8 while saving registry tag '%s'", tag);
+      v = g_strdup ("[ERROR: invalid UTF-8]");
+    }
 
     ret = gst_registry_save (registry, "%s<%s>%s</%s>\n", prefix, tag, v, tag);
     g_free (v);