GNOME Bugzilla – Bug 685691
glib evaluates non-documented environment variable CHARSET and segfaults on unexpected values
Last modified: 2018-02-01 17:41:01 UTC
glib evaluates the (at least in http://developer.gnome.org/glib/2.32/glib-running.html) not documented environment variable "CHARSET" (in the function g_utf8_get_charset_internal gcharset.c). Setting it to an unexpeted value leads to errors: $ export CHARSET="Spanish Inquisition" $./gvctn a GLib: Cannot convert message: Conversion from character set 'UTF-8' to 'Spanish Inquisition' is not supported option parsing failed: Could not open converter from 'Spanish Inquisition' to 'UTF-8' or worse: $ gcalctool -s 1+1 Segmentation fault Without the CHARSET variable everything works fine. IMHO the use of the CHARSET variable should be better documented, if it is necessary at all
*** Bug 685701 has been marked as a duplicate of this bug. ***
This has been in glib from the very first commit. I on't think it adds much value. Documenting it would seem to.give too much of an appearance of usefulness. Removing it might break some decades-old code...
I don’t see a bug here: by setting CHARSET, you are effectively saying that all input and output is in that character set (including command line arguments). When iconv() can’t convert to/from that charset (because it doesn’t exist), it’s correct that an error is printed. The crash in gcalctool is because it is not handling errors from g_locale_to_utf8() or g_utf8_to_locale() properly. With the latest version of gnome-calculator, this appears to just be a couple of critical warnings rather than a crash, but I’ve filed bug #793098 anyway. I don’t know exactly where $CHARSET is used, but it is mentioned in the SUS as being used by ‘widely used command interpreters and applications’, so we should probably keep support for it: http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html I’ll update the documentation to mention it (but not encourage its use).
(In reply to Philip Withnall from comment #3) > I’ll update the documentation to mention it (but not encourage its use). Done: commit b6d1c128b3bfdd7b09f0e3598f41edad21a3c1cc (HEAD -> master, origin/master, origin/HEAD) Author: Philip Withnall <withnall@endlessm.com> Date: Thu Feb 1 17:38:28 2018 +0000 gcharset: Mention the environment variables queried by g_get_charset() Signed-off-by: Philip Withnall <withnall@endlessm.com> Reviewed-by: nobody glib/gcharset.c | 4 ++++ 1 file changed, 4 insertions(+)