gh-146092: Handle _PyFrame_GetFrameObject() failures properly (#146124)

* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling.
* _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals()
  error.
This commit is contained in:
Victor Stinner 2026-03-18 18:27:52 +01:00 committed by GitHub
parent 724c7c8146
commit e1e4852133
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 8 deletions

View file

@ -2237,15 +2237,19 @@ _PyEval_ExceptionGroupMatch(_PyInterpreterFrame *frame, PyObject* exc_value,
return -1;
}
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
if (f != NULL) {
PyObject *tb = _PyTraceBack_FromFrame(NULL, f);
if (tb == NULL) {
Py_DECREF(wrapped);
return -1;
}
PyException_SetTraceback(wrapped, tb);
Py_DECREF(tb);
if (f == NULL) {
Py_DECREF(wrapped);
return -1;
}
PyObject *tb = _PyTraceBack_FromFrame(NULL, f);
if (tb == NULL) {
Py_DECREF(wrapped);
return -1;
}
PyException_SetTraceback(wrapped, tb);
Py_DECREF(tb);
*match = wrapped;
}
*rest = Py_NewRef(Py_None);
@ -2620,6 +2624,11 @@ PyEval_GetLocals(void)
if (PyFrameLocalsProxy_Check(locals)) {
PyFrameObject *f = _PyFrame_GetFrameObject(current_frame);
if (f == NULL) {
Py_DECREF(locals);
return NULL;
}
PyObject *ret = f->f_locals_cache;
if (ret == NULL) {
ret = PyDict_New();