mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-38588: Fix possible crashes in dict and list when calling PyObject_RichCompareBool (GH-17734)
Take strong references before calling PyObject_RichCompareBool to protect against the case where the object dies during the call.
This commit is contained in:
parent
ee9ff05ec2
commit
2d5bf568ea
5 changed files with 47 additions and 1 deletions
|
@ -2662,8 +2662,15 @@ list_richcompare(PyObject *v, PyObject *w, int op)
|
|||
|
||||
/* Search for the first index where items are different */
|
||||
for (i = 0; i < Py_SIZE(vl) && i < Py_SIZE(wl); i++) {
|
||||
PyObject *vitem = vl->ob_item[i];
|
||||
PyObject *witem = wl->ob_item[i];
|
||||
|
||||
Py_INCREF(vitem);
|
||||
Py_INCREF(witem);
|
||||
int k = PyObject_RichCompareBool(vl->ob_item[i],
|
||||
wl->ob_item[i], Py_EQ);
|
||||
Py_DECREF(vitem);
|
||||
Py_DECREF(witem);
|
||||
if (k < 0)
|
||||
return NULL;
|
||||
if (!k)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue