[Python-checkins] r76625 - in python/trunk: Lib/test/test_locale.py Misc/NEWS Modules/_localemodule.c
amaury.forgeotdarc
python-checkins at python.org
Tue Dec 1 22:51:05 CET 2009
Author: amaury.forgeotdarc
Date: Tue Dec 1 22:51:04 2009
New Revision: 76625
Log:
#7419: Fix a crash on Windows in locale.setlocale() when the category
is outside the allowed range.
Modified:
python/trunk/Lib/test/test_locale.py
python/trunk/Misc/NEWS
python/trunk/Modules/_localemodule.c
Modified: python/trunk/Lib/test/test_locale.py
==============================================================================
--- python/trunk/Lib/test/test_locale.py (original)
+++ python/trunk/Lib/test/test_locale.py Tue Dec 1 22:51:04 2009
@@ -360,6 +360,17 @@
# test crasher from bug #3303
self.assertRaises(TypeError, locale.strcoll, u"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/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Tue Dec 1 22:51:04 2009
@@ -12,10 +12,13 @@
Core and Builtins
-----------------
+- Issue #7419: setlocale() could crash the interpreter on Windows when called
+ with invalid values.
+
- Issue #3382: 'F' formatting for float and complex now convert the
result to upper case. This only affects 'inf' and 'nan', since 'f'
no longer converts to 'g' for large values.
-
+
- Remove switch from "%f" formatting to "%g" formatting for floats
larger than 1e50 in absolute value.
Modified: python/trunk/Modules/_localemodule.c
==============================================================================
--- python/trunk/Modules/_localemodule.c (original)
+++ python/trunk/Modules/_localemodule.c Tue Dec 1 22:51:04 2009
@@ -163,6 +163,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