This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: invalid use of setlocale
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: loewis Nosy List: akitada, brett.cannon, georg.brandl, loewis, sbrabec
Priority: normal Keywords: patch

Created on 2003-09-11 15:46 by sbrabec, last changed 2022-04-10 16:11 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Python-2.3-setlocale.patch sbrabec, 2003-09-11 15:46 Python-2.3-setlocale.patch
Messages (6)
msg44605 - (view) Author: Stanislav Brabec (sbrabec) Date: 2003-09-11 15:46
char *oldloc=setlocale(LC_CTYPE,NULL);
setlocale(LC_CTYPE, "C");
setlocale(LC_CTYPE, oldloc);

can cause strange problems.

The glibc documentation clearly states, that you must
make your own copy of the string.

From glibc docs:
setlocale()

RETURN VALUE
       ... This  string  may  be allocated  in static
storage. ...

It means, that subsequent call of setlocale can
overwrite this string. And since glibc-2.3 it does.

There is a fix.
msg44606 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-09-29 01:46
Logged In: YES 
user_id=357491

'C: A Reference Manual' also suggests copying the string in fear of 
possible mucking with the string that is pointed to by the 
setlocale() call.

Since this has a patch already I am changing this to a patch.

And as for the patch, it does use strdup() which is not ANSI C.  I 
know that there a couple of places that do use strdup(), but I am 
not sure if that is really proper.  Requires asking python-dev.
msg44607 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-09-29 02:19
Logged In: YES 
user_id=357491

OK, I found that we have our own definition of strdup() that 
configure.in has used if it is not defined by the C library, so that 
issue is clear.
msg44608 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-11-13 07:44
Logged In: YES 
user_id=21627

The patch was slightly outdated, so I have updated it, and
committed it as

readline.c 2.64.6.1
pythonrun.c 2.195.6.3
readline.c 2.66
pythonrun.c 2.199
msg82850 - (view) Author: Akira Kitada (akitada) * Date: 2009-02-27 17:26
If I'm not mistaken, this bug seems to be fre-introduced in
"release30-maint/Modules/python.c".
It could be fixed in just as it was before.
msg82855 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-02-27 17:54
Fixed in r70029, merged to 3.0 in r70030.
History
Date User Action Args
2022-04-10 16:11:07adminsetgithub: 39217
2009-02-27 17:54:20georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
resolution: fixed
messages: + msg82855
2009-02-27 17:50:28georg.brandlsetstatus: closed -> open
resolution: accepted -> (no value)
2009-02-27 17:26:24akitadasetnosy: + akitada
type: behavior
messages: + msg82850
components: + Interpreter Core, - None
versions: + Python 2.6, Python 3.0, Python 3.1, Python 2.7
2003-09-11 15:46:23sbrabeccreate