[glib/glib-2-28] GVariant: Better handling of invalid UTF-8
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-28] GVariant: Better handling of invalid UTF-8
- Date: Sat, 21 May 2011 04:01:52 +0000 (UTC)
commit 5367f90c670a7fb18ebf47769bbe87e346da7afc
Author: Ryan Lortie <desrt desrt ca>
Date: Wed May 4 18:12:31 2011 +0200
GVariant: Better handling of invalid UTF-8
g_variant_new_string() hits a g_return_if_fail() when given invalid
UTF-8. That's certainly the right thing to do, but
g_variant_builder_add() uses this function internally and crashes when
it returns NULL due to the user passing a non-utf8 string.
We can protect the internal code by returning "[Invalid UTF-8]" in this
case while also making the problem easier to debug (and less fatal).
Closes #632631.
glib/gvariant.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/glib/gvariant.c b/glib/gvariant.c
index e9cfcda..b822d17 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -3687,7 +3687,16 @@ g_variant_valist_new_nnp (const gchar **str,
}
case 's':
- return g_variant_new_string (ptr);
+ {
+ GVariant *value;
+
+ value = g_variant_new_string (ptr);
+
+ if (value == NULL)
+ value = g_variant_new_string ("[Invalid UTF-8]");
+
+ return value;
+ }
case 'o':
return g_variant_new_object_path (ptr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]