Skip to content

Commit 33bb297

Browse files
[3.15] Fix ignored error returns in sys initialization, _ctypes and _interpchannels (GH-160614) (#160711)
(cherry picked from commit c5d0978)
1 parent 1a31558 commit 33bb297

3 files changed

Lines changed: 34 additions & 14 deletions

File tree

‎Modules/_ctypes/_ctypes.c‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,22 +2497,30 @@ PyCSimpleType_init(PyObject *self, PyObject *args, PyObject *kwds)
24972497
}
24982498
assert(sw_info);
24992499
#ifdef WORDS_BIGENDIAN
2500-
PyObject_SetAttrString(self, "__ctype_le__", swapped);
2501-
PyObject_SetAttrString(self, "__ctype_be__", self);
2502-
PyObject_SetAttrString(swapped, "__ctype_be__", self);
2503-
PyObject_SetAttrString(swapped, "__ctype_le__", swapped);
2500+
if (PyObject_SetAttrString(self, "__ctype_le__", swapped) < 0 ||
2501+
PyObject_SetAttrString(self, "__ctype_be__", self) < 0 ||
2502+
PyObject_SetAttrString(swapped, "__ctype_be__", self) < 0 ||
2503+
PyObject_SetAttrString(swapped, "__ctype_le__", swapped) < 0)
2504+
{
2505+
Py_DECREF(swapped);
2506+
return -1;
2507+
}
25042508
/* We are creating the type for the OTHER endian */
25052509
sw_info->format = _ctypes_alloc_format_string("<", stginfo->format+1);
25062510
#else
2507-
PyObject_SetAttrString(self, "__ctype_be__", swapped);
2508-
PyObject_SetAttrString(self, "__ctype_le__", self);
2509-
PyObject_SetAttrString(swapped, "__ctype_le__", self);
2510-
PyObject_SetAttrString(swapped, "__ctype_be__", swapped);
2511+
if (PyObject_SetAttrString(self, "__ctype_be__", swapped) < 0 ||
2512+
PyObject_SetAttrString(self, "__ctype_le__", self) < 0 ||
2513+
PyObject_SetAttrString(swapped, "__ctype_le__", self) < 0 ||
2514+
PyObject_SetAttrString(swapped, "__ctype_be__", swapped) < 0)
2515+
{
2516+
Py_DECREF(swapped);
2517+
return -1;
2518+
}
25112519
/* We are creating the type for the OTHER endian */
25122520
sw_info->format = _ctypes_alloc_format_string(">", stginfo->format+1);
25132521
#endif
25142522
Py_DECREF(swapped);
2515-
if (PyErr_Occurred()) {
2523+
if (sw_info->format == NULL) {
25162524
return -1;
25172525
}
25182526
};

‎Modules/_interpchannelsmodule.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,7 +2638,7 @@ _channelid_shared(PyThreadState *tstate, PyObject *obj, _PyXIData_t *data)
26382638
if (st == NULL) {
26392639
return -1;
26402640
}
2641-
if (!PyObject_IsInstance(obj, (PyObject *)st->ChannelIDType)) {
2641+
if (!PyObject_TypeCheck(obj, st->ChannelIDType)) {
26422642
PyErr_Format(PyExc_TypeError,
26432643
"'_id' attribute must be an %N object, not %T",
26442644
st->ChannelIDType, obj);

‎Python/pylifecycle.c‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,8 +3183,14 @@ init_sys_streams(PyThreadState *tstate)
31833183
config->stdio_errors);
31843184
if (std == NULL)
31853185
goto error;
3186-
PySys_SetObject("__stdin__", std);
3187-
_PySys_SetAttr(&_Py_ID(stdin), std);
3186+
if (PySys_SetObject("__stdin__", std) < 0) {
3187+
Py_DECREF(std);
3188+
goto error;
3189+
}
3190+
if (_PySys_SetAttr(&_Py_ID(stdin), std) < 0) {
3191+
Py_DECREF(std);
3192+
goto error;
3193+
}
31883194
Py_DECREF(std);
31893195

31903196
/* Set sys.stdout */
@@ -3194,8 +3200,14 @@ init_sys_streams(PyThreadState *tstate)
31943200
config->stdio_errors);
31953201
if (std == NULL)
31963202
goto error;
3197-
PySys_SetObject("__stdout__", std);
3198-
_PySys_SetAttr(&_Py_ID(stdout), std);
3203+
if (PySys_SetObject("__stdout__", std) < 0) {
3204+
Py_DECREF(std);
3205+
goto error;
3206+
}
3207+
if (_PySys_SetAttr(&_Py_ID(stdout), std) < 0) {
3208+
Py_DECREF(std);
3209+
goto error;
3210+
}
31993211
Py_DECREF(std);
32003212

32013213
#if 1 /* Disable this if you have trouble debugging bootstrap stuff */

0 commit comments

Comments
 (0)