diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-09-03 15:05:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-03 15:05:18 (GMT) |
commit | 8ea09110d413829f71d979d8c7073008cb87fb03 (patch) | |
tree | bf2072da77a058acc78fa508843bee7b988aba37 /Python | |
parent | f01b2a1b84ee08df73a78cf1017eecf15e3cb995 (diff) | |
download | cpython-8ea09110d413829f71d979d8c7073008cb87fb03.zip cpython-8ea09110d413829f71d979d8c7073008cb87fb03.tar.gz cpython-8ea09110d413829f71d979d8c7073008cb87fb03.tar.bz2 |
_Py_CoerceLegacyLocale() restores LC_CTYPE on fail (GH-9044)
bpo-34544: If _Py_CoerceLegacyLocale() fails to coerce the C locale,
restore the LC_CTYPE locale to the its previous value.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pylifecycle.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 7d17f2e..33ca802 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -363,6 +363,13 @@ void _Py_CoerceLegacyLocale(int warn) { #ifdef PY_COERCE_C_LOCALE + char *oldloc = NULL; + + oldloc = _PyMem_RawStrdup(setlocale(LC_CTYPE, NULL)); + if (oldloc == NULL) { + return; + } + const char *locale_override = getenv("LC_ALL"); if (locale_override == NULL || *locale_override == '\0') { /* LC_ALL is also not set (or is set to an empty string) */ @@ -384,11 +391,16 @@ defined(HAVE_LANGINFO_H) && defined(CODESET) #endif /* Successfully configured locale, so make it the default */ _coerce_default_locale_settings(warn, target); - return; + goto done; } } } /* No C locale warning here, as Py_Initialize will emit one later */ + + setlocale(LC_CTYPE, oldloc); + +done: + PyMem_RawFree(oldloc); #endif } |