]> granicus.if.org Git - python/commitdiff
Merged revisions 74046 via svnmerge from
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Fri, 17 Jul 2009 07:02:18 +0000 (07:02 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Fri, 17 Jul 2009 07:02:18 +0000 (07:02 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r74046 | hirokazu.yamamoto | 2009-07-17 15:55:42 +0900 | 13 lines

  Merged revisions 74040,74042 via svnmerge from
  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 4bcc210f989fe5b8f9c6fee35b5b2fe5641f6b13..292c018ca2233537743512885d48f78f70d2628c 100644 (file)
@@ -338,6 +338,20 @@ 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 0009115dab2ca5da8107ee4c0cc694c4d2572538..2f9c12a4ec8991d781a98618498abcc647906cf2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,8 @@ C-API
 Library
 -------
 
+- Issue #6415: Fixed warnings.warn sagfault on bad formatted string.
+
 - Issue #6358: The exit status of a command started with os.popen() was
   reported differently than it did with python 2.x.
 
index da52e357c3eeee649c0239c105e5cbbf9ec377e2..ef7f373bddcd92ba9cf4d432f4fa749b74effb00 100644 (file)
@@ -320,6 +320,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 {