After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 139030 - gmessage:glog crash due to wrong assumption about GStrings
gmessage:glog crash due to wrong assumption about GStrings
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.4.x
Other Linux
: High major
: ---
Assigned To: gtkdev
gtkdev
: 139441 139452 139679 139741 142111 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-04-04 13:53 UTC by Christophe Saout
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
recode escape_string, hopefully fixing this issue (2.46 KB, patch)
2004-04-09 01:56 UTC, Mariano Suárez-Alvarez
none Details | Review
Same patch, only with my propositional calculus right, hopefully (2.46 KB, patch)
2004-04-09 02:04 UTC, Mariano Suárez-Alvarez
none Details | Review
full gdb backtrace from glib2 with patch applied (29.63 KB, text/plain)
2004-04-25 11:22 UTC, kir
  Details

Description Christophe Saout 2004-04-04 13:53:35 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);
Comment 1 Owen Taylor 2004-04-08 11:40:47 UTC
*** Bug 139441 has been marked as a duplicate of this bug. ***
Comment 2 Owen Taylor 2004-04-08 11:40:57 UTC
*** Bug 139452 has been marked as a duplicate of this bug. ***
Comment 3 Mariano Suárez-Alvarez 2004-04-09 01:53:50 UTC
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)
Comment 4 Mariano Suárez-Alvarez 2004-04-09 01:56:34 UTC
Created attachment 26493 [details] [review]
recode escape_string, hopefully fixing this issue
Comment 5 Mariano Suárez-Alvarez 2004-04-09 02:04:40 UTC
Created attachment 26494 [details] [review]
Same patch, only with my propositional calculus right, hopefully
Comment 6 Wang WenRui 2004-04-09 15:38:17 UTC
yes, it works with g_assert (g_utf8_validate (message, -1, NULL)) commented out.
Comment 7 Mariano Suárez-Alvarez 2004-04-11 20:22:07 UTC
*** Bug 139741 has been marked as a duplicate of this bug. ***
Comment 8 kir 2004-04-25 11:19:11 UTC
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.
Comment 9 kir 2004-04-25 11:22:06 UTC
Created attachment 27065 [details]
full gdb backtrace from glib2 with patch applied
Comment 10 kir 2004-04-25 11:29:55 UTC
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)?
Comment 11 Mariano Suárez-Alvarez 2004-06-22 13:10:55 UTC
*** Bug 139679 has been marked as a duplicate of this bug. ***
Comment 12 Mariano Suárez-Alvarez 2004-11-01 07:23:33 UTC
*** Bug 142111 has been marked as a duplicate of this bug. ***