]> granicus.if.org Git - python/commitdiff
Merged revisions 74040,74042 via svnmerge from
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Fri, 17 Jul 2009 06:33:03 +0000 (06:33 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Fri, 17 Jul 2009 06:33:03 +0000 (06:33 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74040 | hirokazu.yamamoto | 2009-07-17 15:20:46 +0900 | 1 line

  Issue #6415: Fixed warnings.warn sagfault on bad formatted string.
........
  r74042 | hirokazu.yamamoto | 2009-07-17 15:26:54 +0900 | 1 line

  NEWS about r74040.
........

Lib/test/test_warnings.py
Misc/NEWS
Python/_warnings.c

index b37cdf7788ec7143d6ab2b50ffa2db2b6d10f6c0..1f5d05fb8a110263d9028ae85efb6513cff183b6 100644 (file)
@@ -337,6 +337,19 @@ class WarnTests(unittest.TestCase):
                             self.module.warn_explicit,
                             None, Warning, None, 1, registry=42)
 
+    def test_bad_str(self):
+        # issue 6415
+        # Warnings instance with a bad format string for __str__ should not
+        # trigger a bus error.
+        class BadStrWarning(Warning):
+            """Warning with a bad format string for __str__."""
+            def __str__(self):
+                return ("A bad formatted string %(err)" %
+                        {"err" : "there is no %(err)s"})
+
+        with self.assertRaises(ValueError):
+            self.module.warn(BadStrWarning())
+
 
 class CWarnTests(BaseTest, WarnTests):
     module = c_warnings
index fee9d61495a948291770bc511a4e150626beba70..8e6cbb82bccd13aaaaa423d5f5f84b212599d398 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -62,6 +62,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #6415: Fixed warnings.warn sagfault on bad formatted string.
+
 - Issue #6344: Fixed a crash of mmap.read() when passed a negative argument.
 
 - Issue #5230: pydoc would report no documentation found if a module generated
index 6a970bbb2bb706e79f4e878b00c587baf4353ee6..1f0f58e31d6361adddb187bb5d06f6cefcafee12 100644 (file)
@@ -304,6 +304,8 @@ warn_explicit(PyObject *category, PyObject *message,
     }
     if (rc == 1) {
         text = PyObject_Str(message);
+        if (text == NULL)
+            goto cleanup;
         category = (PyObject*)message->ob_type;
     }
     else {