GNOME Bugzilla – Bug 139030
gmessage:glog crash due to wrong assumption about GStrings
Last modified: 2004-12-22 21:47:04 UTC
Probably hard for you, but this happens on my machine: I'm using de_DE@euro and in gnome-terminal I start joe (the text editor) and press AltGr-3/4/5/6 and some other character and sometimes it will just go boom. I found out that he tries to log something about invalid UTF8 sequences and the assumption pos >= 0 in g_string_erase fails. I quickly found out why: escape_string assumes that the string->str doesn't move when modifying the string (g_string_insert). That's wrong. A possible fix is to temporaryly switch to relative positioning in the slow path. Something like this: diff -Nur glib-2.4.0.orig/glib/gmessages.c glib-2.4.0/glib/gmessages.c --- glib-2.4.0.orig/glib/gmessages.c 2004-03-14 19:54:18.000000000 +0100 +++ glib-2.4.0/glib/gmessages.c 2004-04-04 15:40:24.021198616 +0200 @@ -791,15 +791,16 @@ if (wc == (gunichar)-1 || wc == (gunichar)-2) { gchar *tmp; - - g_string_erase (string, p - string->str, 1); + guint pos = p - string->str; + + g_string_erase (string, pos, 1); /* Emit invalid UTF-8 as hex escapes */ - tmp = g_strdup_printf ("\\x%02x", (guint)(guchar)*p); - g_string_insert (string, p - string->str, tmp); + tmp = g_strdup_printf ("\\x%02x", (guint)(guchar)string->str[pos]); + g_string_insert (string, pos, tmp); g_free (tmp); - p += 4; /* Skip over escape sequence */ + p = &string->str[pos + 4]; /* Skip over escape sequence */ continue; } @@ -815,16 +816,17 @@ if (!safe) { gchar *tmp; - - g_string_erase (string, p - string->str, g_utf8_next_char (p) - p); + guint pos = p - string->str; + + g_string_erase (string, pos, g_utf8_next_char (p) - p); /* Largest char we escape is 0x0a, so we don't have to worry * about 8-digit \Uxxxxyyyy */ tmp = g_strdup_printf ("\\u%04x", wc); - g_string_insert (string, p - string->str, tmp); + g_string_insert (string, pos, tmp); g_free (tmp); - p += 6; /* Skip over escape sequence */ + p = &string->str[pos + 6]; /* Skip over escape sequence */ } else p = g_utf8_next_char (p);
*** Bug 139441 has been marked as a duplicate of this bug. ***
*** Bug 139452 has been marked as a duplicate of this bug. ***
Hmm, in 139441 there problem is rather that vte does not call bind_textdomain_codeset to set the codeset to UTF-8, so that things like g_warning (_("Hello")) break horribly. Doing a g_assert (g_utf8_validate (message, -1, NULL)) in the default_log_handler would not hurt a lot... Here comes a patch which is a bit simpler IMHO that the original code in escape_string, since it does not try to do everything in-place (and it has the assertion)
Created attachment 26493 [details] [review] recode escape_string, hopefully fixing this issue
Created attachment 26494 [details] [review] Same patch, only with my propositional calculus right, hopefully
yes, it works with g_assert (g_utf8_validate (message, -1, NULL)) commented out.
*** Bug 139741 has been marked as a duplicate of this bug. ***
Well, I have recompiled glib-2.4.0 with a patch from comment #5, and that doesn't fix my bug #139741. I will attach a full backtrace now...and, hmm, seems I have no rights to reopen the bug.
Created attachment 27065 [details] full gdb backtrace from glib2 with patch applied
Oh, I'm stupid today. Seems that glib is now calling abort instead of crashing like it was before. So should I file a bug for vte now in order for my gnome-terminal crash to be fixed (or reassign my bug #139741 to gnome-terminal or vte)?
*** Bug 139679 has been marked as a duplicate of this bug. ***
*** Bug 142111 has been marked as a duplicate of this bug. ***