Skip to content

Commit 64f3ca4

Browse files
committed
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 python#7419: Fix a crash on Windows in locale.setlocale() when the category is outside the allowed range. ........
1 parent c2e1cb7 commit 64f3ca4

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

Lib/test/test_locale.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,17 @@ def test_strcoll_3303(self):
353353
self.assertRaises(TypeError, locale.strcoll, "a", None)
354354
self.assertRaises(TypeError, locale.strcoll, b"a", None)
355355

356+
def test_setlocale_category(self):
357+
locale.setlocale(locale.LC_ALL)
358+
locale.setlocale(locale.LC_TIME)
359+
locale.setlocale(locale.LC_CTYPE)
360+
locale.setlocale(locale.LC_COLLATE)
361+
locale.setlocale(locale.LC_MONETARY)
362+
locale.setlocale(locale.LC_NUMERIC)
363+
364+
# crasher from bug #7419
365+
self.assertRaises(locale.Error, locale.setlocale, 12345)
366+
356367

357368
def test_main():
358369
tests = [

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #7419: setlocale() could crash the interpreter on Windows when called
16+
with invalid values.
17+
1518
- Issue #6077: On Windows, files opened with tempfile.TemporaryFile in "wt+"
1619
mode would appear truncated on the first '0x1a' byte (aka. Ctrl+Z).
1720

Modules/_localemodule.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
133133
if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))
134134
return NULL;
135135

136+
#if defined(MS_WINDOWS)
137+
if (category < LC_MIN || category > LC_MAX)
138+
{
139+
PyErr_SetString(Error, "invalid locale category");
140+
return NULL;
141+
}
142+
#endif
143+
136144
if (locale) {
137145
/* set locale */
138146
result = setlocale(category, locale);

0 commit comments

Comments
 (0)