[Python-checkins] r76626 - in python/branches/py3k: Lib/test/test_locale.py Misc/NEWS Modules/_localemodule.c
amaury.forgeotdarc
python-checkins at python.org
Tue Dec 1 22:59:19 CET 2009
Author: amaury.forgeotdarc
Date: Tue Dec 1 22:59:18 2009
New Revision: 76626
Log:
Merged revisions 76625 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76625 | amaury.forgeotdarc | 2009-12-01 22:51:04 +0100 (mar., 01 déc. 2009) | 3 lines
#7419: Fix a crash on Windows in locale.setlocale() when the category
is outside the allowed range.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/test/test_locale.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Modules/_localemodule.c
Modified: python/branches/py3k/Lib/test/test_locale.py
==============================================================================
--- python/branches/py3k/Lib/test/test_locale.py (original)
+++ python/branches/py3k/Lib/test/test_locale.py Tue Dec 1 22:59:18 2009
@@ -353,6 +353,17 @@
self.assertRaises(TypeError, locale.strcoll, "a", None)
self.assertRaises(TypeError, locale.strcoll, b"a", None)
+ def test_setlocale_category(self):
+ locale.setlocale(locale.LC_ALL)
+ locale.setlocale(locale.LC_TIME)
+ locale.setlocale(locale.LC_CTYPE)
+ locale.setlocale(locale.LC_COLLATE)
+ locale.setlocale(locale.LC_MONETARY)
+ locale.setlocale(locale.LC_NUMERIC)
+
+ # crasher from bug #7419
+ self.assertRaises(locale.Error, locale.setlocale, 12345)
+
def test_main():
tests = [
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Tue Dec 1 22:59:18 2009
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #7419: setlocale() could crash the interpreter on Windows when called
+ with invalid values.
+
- Issue #6077: On Windows, files opened with tempfile.TemporaryFile in "wt+"
mode would appear truncated on the first '0x1a' byte (aka. Ctrl+Z).
Modified: python/branches/py3k/Modules/_localemodule.c
==============================================================================
--- python/branches/py3k/Modules/_localemodule.c (original)
+++ python/branches/py3k/Modules/_localemodule.c Tue Dec 1 22:59:18 2009
@@ -133,6 +133,14 @@
if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))
return NULL;
+#if defined(MS_WINDOWS)
+ if (category < LC_MIN || category > LC_MAX)
+ {
+ PyErr_SetString(Error, "invalid locale category");
+ return NULL;
+ }
+#endif
+
if (locale) {
/* set locale */
result = setlocale(category, locale);
More information about the Python-checkins
mailing list