mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
[3.12] gh-130163: Fix crashes related to PySys_GetObject() (GH-130503) (GH-130556) (GH-130576)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString(). (cherry picked from commit0ef4ffeefd) (cherry picked from commit7c1b76fce8) (cherry picked from commit2ab7e1135a)
This commit is contained in:
parent
6a268a046f
commit
89a79fc919
21 changed files with 506 additions and 162 deletions
|
|
@ -5,6 +5,8 @@
|
|||
#include "pycore_pyerrors.h"
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "pycore_frame.h"
|
||||
#include "pycore_sysmodule.h" // _PySys_GetOptionalAttr()
|
||||
|
||||
#include "clinic/_warnings.c.h"
|
||||
|
||||
#define MODULE_NAME "_warnings"
|
||||
|
|
@ -493,7 +495,7 @@ static void
|
|||
show_warning(PyThreadState *tstate, PyObject *filename, int lineno,
|
||||
PyObject *text, PyObject *category, PyObject *sourceline)
|
||||
{
|
||||
PyObject *f_stderr;
|
||||
PyObject *f_stderr = NULL;
|
||||
PyObject *name;
|
||||
char lineno_str[128];
|
||||
|
||||
|
|
@ -504,8 +506,7 @@ show_warning(PyThreadState *tstate, PyObject *filename, int lineno,
|
|||
goto error;
|
||||
}
|
||||
|
||||
f_stderr = _PySys_GetAttr(tstate, &_Py_ID(stderr));
|
||||
if (f_stderr == NULL) {
|
||||
if (_PySys_GetOptionalAttr(&_Py_ID(stderr), &f_stderr) <= 0) {
|
||||
fprintf(stderr, "lost sys.stderr\n");
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -558,6 +559,7 @@ show_warning(PyThreadState *tstate, PyObject *filename, int lineno,
|
|||
}
|
||||
|
||||
error:
|
||||
Py_XDECREF(f_stderr);
|
||||
Py_XDECREF(name);
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue