Skip to content

Commit 391eb41

Browse files
committed
Backport gh-120298 list_richcompare use after free
This backports the fix to #120298. commit id b884536
1 parent 6d1ab20 commit 391eb41

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix use-after free in ``list_richcompare_impl`` which can be invoked via
2+
some specificly tailored evil input.

Objects/listobject.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,14 @@ list_richcompare(PyObject *v, PyObject *w, int op)
27572757
}
27582758

27592759
/* Compare the final item again using the proper operator */
2760-
return PyObject_RichCompare(vl->ob_item[i], wl->ob_item[i], op);
2760+
PyObject *vitem = vl->ob_item[i];
2761+
PyObject *witem = wl->ob_item[i];
2762+
Py_INCREF(vitem);
2763+
Py_INCREF(witem);
2764+
PyObject *result = PyObject_RichCompare(vl->ob_item[i], wl->ob_item[i], op);
2765+
Py_DECREF(vitem);
2766+
Py_DECREF(witem);
2767+
return result;
27612768
}
27622769

27632770
/*[clinic input]

0 commit comments

Comments
 (0)