summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-09-03 22:17:07 +0200
committerGitHub <noreply@github.com>2018-09-03 22:17:07 +0200
commit84b0129b5e0a0e22aad22ae8db2e3833a228aa57 (patch)
tree95a8efe7723fd56d94f04e908ba45ce9f038448a /Python
parentf4c865eda8f57dedaeaa16530ab6f1024bfb94de (diff)
downloadcpython-git-84b0129b5e0a0e22aad22ae8db2e3833a228aa57.tar.gz
_Py_CoerceLegacyLocale() restores LC_CTYPE on fail (GH-9044) (GH-9046)
bpo-34544: If _Py_CoerceLegacyLocale() fails to coerce the C locale, restore the LC_CTYPE locale to the its previous value. (cherry picked from commit 8ea09110d413829f71d979d8c7073008cb87fb03)
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 539d62a2f0..ba4b54864f 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -475,6 +475,13 @@ void
_Py_CoerceLegacyLocale(const _PyCoreConfig *config)
{
#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) */
@@ -496,11 +503,16 @@ defined(HAVE_LANGINFO_H) && defined(CODESET)
#endif
/* Successfully configured locale, so make it the default */
_coerce_default_locale_settings(config, 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
}