Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4147,6 +4147,15 @@ def test_float_operation_default(self):
@requires_cdecimal
class CContextFlags(ContextFlags, unittest.TestCase):
decimal = C

def test_signaldict_repr(self):
Context = self.decimal.Context
ctx = Context(prec=7)
mapping = ctx.flags
del ctx
with self.assertRaises(ValueError):
repr(mapping)

class PyContextFlags(ContextFlags, unittest.TestCase):
decimal = P

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a heap-use-after-free in the C implementation of :mod:`decimal`
when calling :func:`repr` after deleting the :class:`~decimal.Context`.
10 changes: 10 additions & 0 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,16 @@ static int
context_clear(PyObject *op)
{
PyDecContextObject *self = _PyDecContextObject_CAST(op);
PyDecSignalDictObject *traps = _PyDecSignalDictObject_CAST(self->traps);
PyDecSignalDictObject *flags = _PyDecSignalDictObject_CAST(self->flags);

if (traps != NULL) {
traps->flags = NULL;
}
if (flags != NULL) {
flags->flags = NULL;
}

Py_CLEAR(self->traps);
Py_CLEAR(self->flags);
return 0;
Expand Down
Loading