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 685691 - glib evaluates non-documented environment variable CHARSET and segfaults on unexpected values
glib evaluates non-documented environment variable CHARSET and segfaults on ...
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: i18n
2.32.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-10-07 22:26 UTC by Michael Fischer v. Mollard
Modified: 2018-02-01 17:41 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Michael Fischer v. Mollard 2012-10-07 22:26:19 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
Comment 1 Matthew Barnes 2012-10-09 21:03:31 UTC
*** Bug 685701 has been marked as a duplicate of this bug. ***
Comment 2 Matthias Clasen 2012-10-11 20:29:18 UTC
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...
Comment 3 Philip Withnall 2018-02-01 17:32:32 UTC
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).
Comment 4 Philip Withnall 2018-02-01 17:41:01 UTC
(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(+)