mirror of
https://github.com/python/cpython.git
synced 2025-07-30 06:34:15 +00:00
Issue #6415: Fixed warnings.warn sagfault on bad formatted string.
This commit is contained in:
parent
66da2635ff
commit
e78e5d2e51
2 changed files with 15 additions and 0 deletions
|
@ -327,6 +327,19 @@ class WarnTests(unittest.TestCase):
|
||||||
self.module.warn_explicit,
|
self.module.warn_explicit,
|
||||||
None, Warning, None, 1, registry=42)
|
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):
|
class CWarnTests(BaseTest, WarnTests):
|
||||||
module = c_warnings
|
module = c_warnings
|
||||||
|
|
|
@ -317,6 +317,8 @@ warn_explicit(PyObject *category, PyObject *message,
|
||||||
}
|
}
|
||||||
if (rc == 1) {
|
if (rc == 1) {
|
||||||
text = PyObject_Str(message);
|
text = PyObject_Str(message);
|
||||||
|
if (text == NULL)
|
||||||
|
goto cleanup;
|
||||||
category = (PyObject*)message->ob_type;
|
category = (PyObject*)message->ob_type;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue