crash in g_utf8_validate with GTK 2 gtk_show_uri
The below GTK 2 program causes a crash in g_utf8_validate
, because that
doesn't handle NULL
pointers being passed in and some part of the GTK 2
and GLib stack behind gtk_show_uri
passes a NULL
pointer in some cases.
I don't know if this is a bug in GLib or GTK 2 or both, but I'm filing it against GLib because that is the part of the stack that crashes.
The crash does happen when compiling with GTK 2:
$ gcc helloworld.c -o helloworld -Wall `pkg-config gtk+-2.0 --cflags --libs`
The crash doesn't happen when compiling with GTK 3:
$ gcc helloworld.c -o helloworld -Wall `pkg-config gtk+-3.0 --cflags --libs`
The crash happens on Debian bookworm with GLib 2.74.2-1 and GTK 2.24.33-2.
Here is the code that causes the crash with GTK 2:
#include <gtk/gtk.h>
int main( int argc,
char *argv[] )
{
char *url = "https://lore.kernel.org/linux-man/Y6y%2F0uzFlTpkw%2FVT@mit.edu/";
gtk_init (&argc, &argv);
gtk_show_uri (NULL, url, GDK_CURRENT_TIME, NULL);
gtk_main ();
return 0;
}
Here is a copy of the crash backtrace:
$ gdb -batch -n -ex 'set pagination off' -ex run -ex bt -ex 'bt full' -ex 'thread apply all bt full' --args ./helloworld
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff0fa26c0 (LWP 23362)]
[New Thread 0x7fffebfff6c0 (LWP 23363)]
Thread 1 "helloworld" received signal SIGSEGV, Segmentation fault.
g_utf8_validate (str=str@entry=0x0, max_len=max_len@entry=-1, end=end@entry=0x0) at ../../../glib/gutf8.c:1689
1689 ../../../glib/gutf8.c: No such file or directory.
#0 g_utf8_validate (str=str@entry=0x0, max_len=max_len@entry=-1, end=end@entry=0x0) at ../../../glib/gutf8.c:1689
#1 0x00007ffff7f0bdb8 in get_display_name (info=<optimized out>, file=0x7fffe400f760) at ../../../../../gdk/x11/gdkapplaunchcontext-x11.c:52
#2 _gdk_windowing_get_startup_notify_id (context=<optimized out>, info=0x5555555ad1b0, files=<optimized out>) at ../../../../../gdk/x11/gdkapplaunchcontext-x11.c:318
#3 0x00007ffff7476eaf in g_desktop_app_info_launch_uris_with_spawn (info=info@entry=0x5555555ad1b0 [GDesktopAppInfo], session_bus=session_bus@entry=0x55555568e060 [GDBusConnection], exec_line=0x5555556d32a0 "/usr/lib/firefox-esr/firefox-esr %u", uris=uris@entry=0x7fffffffd520 = {...}, launch_context=launch_context@entry=0x55555562c770 [GdkAppLaunchContext], spawn_flags=spawn_flags@entry=G_SPAWN_SEARCH_PATH, user_setup=0x0, user_setup_data=0x0, pid_callback=0x0, pid_callback_data=0x0, stdin_fd=-1, stdout_fd=-1, stderr_fd=-1, error=0x0) at ../../../gio/gdesktopappinfo.c:2910
#4 0x00007ffff7479bde in g_desktop_app_info_launch_uris_internal (error=0x0, stderr_fd=-1, stdout_fd=-1, stdin_fd=-1, pid_callback_data=0x0, pid_callback=0x0, user_setup_data=0x0, user_setup=0x0, spawn_flags=G_SPAWN_SEARCH_PATH, launch_context=0x55555562c770 [GdkAppLaunchContext], uris=0x7fffffffd520 = {...}, appinfo=0x5555555ad1b0) at ../../../gio/gdesktopappinfo.c:3236
#5 g_desktop_app_info_launch_uris (appinfo=0x5555555ad1b0, uris=0x7fffffffd520 = {...}, launch_context=0x55555562c770 [GdkAppLaunchContext], error=0x0) at ../../../gio/gdesktopappinfo.c:3260
#6 0x00007ffff73f9806 in g_app_info_launch_default_for_uri (uri=uri@entry=0x555555556008 "https://lore.kernel.org/linux-man/Y6y%2F0uzFlTpkw%2FVT@mit.edu/", launch_context=launch_context@entry=0x55555562c770 [GdkAppLaunchContext], error=error@entry=0x0) at ../../../gio/gappinfo.c:1015
#7 0x00007ffff7ba8c76 in IA__gtk_show_uri (screen=0x0, uri=0x555555556008 "https://lore.kernel.org/linux-man/Y6y%2F0uzFlTpkw%2FVT@mit.edu/", timestamp=0, error=0x0) at ../../../../gtk/gtkshow.c:75
#8 0x00005555555551a1 in main ()
```