mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +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
|
|
@ -109,6 +109,7 @@ static const char PyCursesVersion[] = "2.2";
|
|||
#include "Python.h"
|
||||
#include "pycore_long.h" // _PyLong_GetZero()
|
||||
#include "pycore_structseq.h" // _PyStructSequence_NewType()
|
||||
#include "pycore_sysmodule.h" // _PySys_GetOptionalAttrString()
|
||||
|
||||
#ifdef __hpux
|
||||
#define STRICT_SYSV_CURSES
|
||||
|
|
@ -3375,17 +3376,20 @@ _curses_setupterm_impl(PyObject *module, const char *term, int fd)
|
|||
if (fd == -1) {
|
||||
PyObject* sys_stdout;
|
||||
|
||||
sys_stdout = PySys_GetObject("stdout");
|
||||
if (_PySys_GetOptionalAttrString("stdout", &sys_stdout) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sys_stdout == NULL || sys_stdout == Py_None) {
|
||||
PyErr_SetString(
|
||||
PyCursesError,
|
||||
"lost sys.stdout");
|
||||
Py_XDECREF(sys_stdout);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = PyObject_AsFileDescriptor(sys_stdout);
|
||||
|
||||
Py_DECREF(sys_stdout);
|
||||
if (fd == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue