Skip to content

Commit 547f7d9

Browse files
committed
gh-146102: Fix use-after-free and exception leak in crossinterp subsystem
1 parent eca3b26 commit 547f7d9

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

Python/crossinterp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,24 +491,24 @@ _get_xidata(PyThreadState *tstate,
491491
Py_DECREF(obj);
492492
return -1;
493493
}
494-
// Fall back to obj
495-
Py_DECREF(obj);
496494
if (!_PyErr_Occurred(tstate)) {
497495
_set_xid_lookup_failure(tstate, obj, NULL, NULL);
498496
}
497+
Py_DECREF(obj);
499498
return -1;
500499
}
501500
int res = getdata.basic != NULL
502501
? getdata.basic(tstate, obj, xidata)
503502
: getdata.fallback(tstate, obj, fallback, xidata);
504-
Py_DECREF(obj);
505503
if (res != 0) {
506504
PyObject *cause = _PyErr_GetRaisedException(tstate);
507505
assert(cause != NULL);
508506
_set_xid_lookup_failure(tstate, obj, NULL, cause);
509507
Py_XDECREF(cause);
508+
Py_DECREF(obj);
510509
return -1;
511510
}
511+
Py_DECREF(obj);
512512

513513
// Fill in the blanks and validate the result.
514514
_PyXIData_INTERPID(xidata) = PyInterpreterState_GetID(interp);

Python/crossinterp_data_lookup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ _PyXI_UnwrapNotShareableError(PyThreadState * tstate, _PyXI_failure *failure)
100100
if (failure != NULL) {
101101
_PyXI_errcode code = _PyXI_ERR_NOT_SHAREABLE;
102102
if (_PyXI_InitFailure(failure, code, exc) < 0) {
103+
_PyErr_SetRaisedException(tstate, exc);
103104
return -1;
104105
}
105106
}

Python/crossinterp_exceptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ _ensure_notshareableerror(PyThreadState *tstate,
8383
// A NotShareableError instance is already set.
8484
assert(cause == NULL);
8585
_PyErr_SetRaisedException(tstate, ctx);
86+
return;
8687
}
8788
}
8889
else {

0 commit comments

Comments
 (0)