mirror of
https://github.com/python/cpython.git
synced 2026-02-27 17:41:12 +00:00
gh-143403: Fix a UAF in _BINARY_OP_INPLACE_ADD_UNICODE (GH-143404)
Fix a UAF in `_BINARY_OP_INPLACE_ADD_UNICODE`
This commit is contained in:
parent
9609574e7f
commit
6116d70bbd
3 changed files with 21 additions and 24 deletions
|
|
@ -802,15 +802,18 @@ dummy_func(
|
|||
*/
|
||||
assert(Py_REFCNT(left_o) >= 2 || !PyStackRef_IsHeapSafe(left));
|
||||
PyObject *temp = PyStackRef_AsPyObjectSteal(*target_local);
|
||||
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
|
||||
PyUnicode_Append(&temp, right_o);
|
||||
PyStackRef_CLOSE_SPECIALIZED(right, _PyUnicode_ExactDealloc);
|
||||
DEAD(right);
|
||||
PyObject *right_o = PyStackRef_AsPyObjectSteal(right);
|
||||
/* gh-143403: It's critical to close this reference *before*
|
||||
* we append. Otherwise, append can move the underlying
|
||||
* unicode object, which will cause a use after free!
|
||||
*/
|
||||
PyStackRef_CLOSE_SPECIALIZED(left, _PyUnicode_ExactDealloc);
|
||||
DEAD(left);
|
||||
PyUnicode_Append(&temp, right_o);
|
||||
_Py_DECREF_SPECIALIZED(right_o, _PyUnicode_ExactDealloc);
|
||||
*target_local = PyStackRef_NULL;
|
||||
ERROR_IF(temp == NULL);
|
||||
res = PyStackRef_FromPyObjectSteal(temp);
|
||||
*target_local = PyStackRef_NULL;
|
||||
}
|
||||
|
||||
op(_GUARD_BINARY_OP_EXTEND, (descr/4, left, right -- left, right)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue