Skip to content

Commit

Permalink
Backport pythongh-120298 list_richcompare use after free
Browse files Browse the repository at this point in the history
This backports the fix to python#120298.
commit id b884536
  • Loading branch information
gpshead committed Jul 3, 2024
1 parent 6d1ab20 commit 391eb41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix use-after free in ``list_richcompare_impl`` which can be invoked via
some specificly tailored evil input.
9 changes: 8 additions & 1 deletion Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,14 @@ list_richcompare(PyObject *v, PyObject *w, int op)
}

/* Compare the final item again using the proper operator */
return PyObject_RichCompare(vl->ob_item[i], wl->ob_item[i], op);
PyObject *vitem = vl->ob_item[i];
PyObject *witem = wl->ob_item[i];
Py_INCREF(vitem);
Py_INCREF(witem);
PyObject *result = PyObject_RichCompare(vl->ob_item[i], wl->ob_item[i], op);
Py_DECREF(vitem);
Py_DECREF(witem);
return result;
}

/*[clinic input]
Expand Down

0 comments on commit 391eb41

Please sign in to comment.