Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-110365: Fix error overwrite in termios.tcsetattr #110366

Merged
merged 10 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-110365: Fix error overwrite in termios.tcsetattr
  • Loading branch information
sobolevn committed Oct 4, 2023
commit 4d5ae6663203ff4ab646933d11a3aa57b772f3ed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`termios.tcsetattr` bug that was overwritting existing errors
during parsing integets from ``term`` list.
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 22 additions & 8 deletions Modules/termios.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,31 @@ termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)
return PyErr_SetFromErrno(state->TermiosError);
}

mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0));
mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1));
mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2));
mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3));
speed_t ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4));
speed_t ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5));
PyObject *cc = PyList_GetItem(term, 6);
long item;
#define SAFE_LONG_ITEM(obj) \
item = PyLong_AsLong(obj); \
if (PyErr_Occurred()) { \
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
return NULL; \
}

SAFE_LONG_ITEM(PyList_GET_ITEM(term, 0));
mode.c_iflag = (tcflag_t) item;
SAFE_LONG_ITEM(PyList_GET_ITEM(term, 1));
mode.c_oflag = (tcflag_t) item;
SAFE_LONG_ITEM(PyList_GET_ITEM(term, 2));
mode.c_cflag = (tcflag_t) item;
SAFE_LONG_ITEM(PyList_GET_ITEM(term, 3));
mode.c_lflag = (tcflag_t) item;
SAFE_LONG_ITEM(PyList_GET_ITEM(term, 4));
speed_t ispeed = (speed_t) item;
SAFE_LONG_ITEM(PyList_GET_ITEM(term, 5));
speed_t ospeed = (speed_t) item;
#undef SAFE_LONG_ITEM

PyObject *cc = PyList_GET_ITEM(term, 6);
if (PyErr_Occurred()) {
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
return NULL;
}

if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
PyErr_Format(PyExc_TypeError,
"tcsetattr: attributes[6] must be %d element list",
Expand Down
Loading