GNOME Bugzilla – Bug 760304
fix crash when invalid locale is found.
Last modified: 2016-01-11 13:23:08 UTC
Created attachment 318447 [details] [review] fix sigsegv crash When a invalid locale is detected like "kk_Cyrl_KZ.UTF-8" in gnome_parse_locale(), language is not set. construct_language_name() will then try to access elements in language that don't exist, check if language is !NULL before doing this, like territory, codeset and modifier doing. (lldb) s (gnome-control-center:249): GnomeDesktop-WARNING **: locale 'kk_Cyrl_KZ.UTF-8' isn't valid Process 249 stopped * thread #1: tid = 102670, 0x0000000804756c2f libgnome-desktop-3.so.12`construct_language_name(language=0x0000000000000000, territory=0x0000000000000000, codeset=0x0000000000000000, modifier=0x0000000000000000) + 31 at gnome-languages.c:232, stop reason = signal SIGSEGV: invalid address (fault address: 0x0) frame #0: 0x0000000804756c2f libgnome-desktop-3.so.12`construct_language_name(language=0x0000000000000000, territory=0x0000000000000000, codeset=0x0000000000000000, modifier=0x0000000000000000) + 31 at gnome-languages.c:232 229 { 230 char *name; 231 -> 232 g_assert (language[0] != 0); 233 g_assert (territory == NULL || territory[0] != 0); 234 g_assert (codeset == NULL || codeset[0] != 0); 235 g_assert (modifier == NULL || modifier[0] != 0); (lldb)
Created attachment 318494 [details] [review] gnome-languages: Return early if the locale didn't parse correctly There's no point in going further if we can't parse the locale and we can prevent crashes in some corner cases this way.
Review of attachment 318447 [details] [review]: Thanks, can you re-submit this with the change below ? I'll also push this other patch to return early in this case. Not checking the return value of gnome_parse_locale() is the real problem here ::: libgnome-desktop/gnome-languages.c @@ +230,3 @@ char *name; + g_assert (language == NULL || language[0] != 0); language can't be NULL for this function though since its purpose is to get us a normalized locale string and a locale string without language doesn't make sense so, if anything this would need to be changed to (language != NULL && language[0] != 0)
Created attachment 318711 [details] [review] check if language is !NULL I took your text as basis for the patch and removed the part that applies to your proposed second patch.
Thanks, all pushed. Note that I edited your patch because the condition should be && in this case. 09d331a..cae6091 gnome-3-18 -> gnome-3-18 a07c8ce..4d9a6eb master -> master