]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-146091: Fix NULL check in termios.tcsetwinsize (#146147)
authorOkiemute Enato <51956662+okiemute04@users.noreply.github.com>
Thu, 19 Mar 2026 10:50:18 +0000 (03:50 -0700)
committerGitHub <noreply@github.com>
Thu, 19 Mar 2026 10:50:18 +0000 (16:20 +0530)
Misc/NEWS.d/next/Library/2026-03-18-16-58-17.gh-issue-146091.lBbo1L.rst [new file with mode: 0644]
Modules/termios.c

diff --git a/Misc/NEWS.d/next/Library/2026-03-18-16-58-17.gh-issue-146091.lBbo1L.rst b/Misc/NEWS.d/next/Library/2026-03-18-16-58-17.gh-issue-146091.lBbo1L.rst
new file mode 100644 (file)
index 0000000..2ed3ea8
--- /dev/null
@@ -0,0 +1,3 @@
+Fix a bug in :func:`termios.tcsetwinsize` where passing a sequence that
+raises an exception in ``__getitem__`` would cause a :exc:`SystemError`
+instead of propagating the original exception.
index b4eb06cf8ae8acf6adc830a08f4af44f63fcd7e4..95b9c920f39c1265aae4d788752352ca7f4ce1aa 100644 (file)
@@ -500,19 +500,24 @@ termios_tcsetwinsize_impl(PyObject *module, int fd, PyObject *winsz)
     PyObject *tmp_item;
     long winsz_0, winsz_1;
     tmp_item = PySequence_GetItem(winsz, 0);
+    if (tmp_item == NULL) {
+        return NULL;
+    }
     winsz_0 = PyLong_AsLong(tmp_item);
+    Py_DECREF(tmp_item);
     if (winsz_0 == -1 && PyErr_Occurred()) {
-        Py_XDECREF(tmp_item);
         return NULL;
     }
-    Py_XDECREF(tmp_item);
     tmp_item = PySequence_GetItem(winsz, 1);
+    if (tmp_item == NULL) {
+        return NULL;
+    }
     winsz_1 = PyLong_AsLong(tmp_item);
+    Py_DECREF(tmp_item);
     if (winsz_1 == -1 && PyErr_Occurred()) {
-        Py_XDECREF(tmp_item);
         return NULL;
     }
-    Py_XDECREF(tmp_item);
+
 
     termiosmodulestate *state = PyModule_GetState(module);