Skip to content

Commit acdb9a7

Browse files
[3.13] gh-156189: Fix a crash when deleting frame.f_trace_opcodes (GH-156190)
The setter passed the value to PyBool_Check() without checking it for NULL.
1 parent 3d937eb commit acdb9a7

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_frame.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ def test_locals_clear_locals(self):
219219
self.assertEqual(outer.f_locals, {})
220220
self.assertEqual(inner.f_locals, {})
221221

222+
def test_f_trace_opcodes_del(self):
223+
f, _, _ = self.make_frames()
224+
f.f_trace_opcodes = True
225+
with self.assertRaisesRegex(AttributeError, 'cannot delete attribute'):
226+
del f.f_trace_opcodes
227+
# a failed deletion does not change the value
228+
self.assertIs(f.f_trace_opcodes, True)
229+
222230
def test_f_lineno_del_segfault(self):
223231
f, _, _ = self.make_frames()
224232
with self.assertRaises(AttributeError):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash when deleting the :attr:`~frame.f_trace_opcodes` attribute of
2+
a frame object. It now raises :exc:`AttributeError`.

Objects/frameobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ frame_gettrace_opcodes(PyFrameObject *f, void *closure)
979979
static int
980980
frame_settrace_opcodes(PyFrameObject *f, PyObject* value, void *Py_UNUSED(ignored))
981981
{
982+
if (value == NULL) {
983+
PyErr_SetString(PyExc_AttributeError,
984+
"cannot delete attribute f_trace_opcodes");
985+
return -1;
986+
}
982987
if (!PyBool_Check(value)) {
983988
PyErr_SetString(PyExc_TypeError,
984989
"attribute value type must be bool");

0 commit comments

Comments
 (0)