]> granicus.if.org Git - python/commitdiff
Merged revisions 76626 via svnmerge from
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 1 Dec 2009 22:03:44 +0000 (22:03 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 1 Dec 2009 22:03:44 +0000 (22:03 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r76626 | amaury.forgeotdarc | 2009-12-01 22:59:18 +0100 (mar., 01 déc. 2009) | 10 lines

  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.
  ........
................

Lib/test/test_locale.py
Misc/NEWS
Modules/_localemodule.c

index 8dfaf9052d75bb6923c52e9e6598467d44aad49e..8c17f8770c7419991fd1786f990a13cac6a6347b 100644 (file)
@@ -353,6 +353,17 @@ class TestMiscellaneous(unittest.TestCase):
         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 = [
index ddd10d7786aafb33f8feca212a65359ce0fdff5e..b8f2cba173b67b6c33a8f5f905c59a8089540116 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.1.2?
 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).
 
index fa6ab8fc6d89c048a952bf4092c4269f355c5061..aabc3ac864650d11dccd977a0613ded2d1efedc4 100644 (file)
@@ -133,6 +133,14 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
     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);