Skip to content

system/region: Prevent preview crash from accessing invalid pointer

In !2051 (merged), we switch back to real locale before setting the label text, however, according to nl_langinfo's manpage, the returned pointer could be invalid after switching locale or creating new locale, so the program may crash.

To fix this, we save the result before switching locale, so we won't access the invalid pointer after switching locale.

Additional Info

The link to the original bug: https://bugzilla.suse.com/show_bug.cgi?id=1218528

When it crash, the following output is printed by gdb:

Thread 1 "gnome-control-c" received signal SIGSEGV, Segmentation fault.
0x0000555555637b71 in update_format_examples (self=0x55555d2760b0) at ../panels/region/cc-format-preview.c:143
143	  if (fmt && *fmt == 2)
(gdb) print fmt
$1 = (const gchar *) 0x7fffc4f4f010 <error: Cannot access memory at address 0x7fffc4f4f010>
(gdb) print *fmt
Cannot access memory at address 0x7fffc4f4f010
(gdb) 

Cc @velsinki because I consider this is a missing part of !2051 (merged).

Edited by Alynx Zhou

Merge request reports