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
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Erlend E. Aasland <[email protected]>
  • Loading branch information
sobolevn and erlend-aasland authored Oct 5, 2023
commit 33d86b2309f9d68ce114123f626dbc649fcba080
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Fix :func:`termios.tcsetattr` bug that was overwritting existing errors
during parsing integets from ``term`` list.
during parsing integers from ``term`` list.
38 changes: 17 additions & 21 deletions Modules/termios.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,21 @@
return PyErr_SetFromErrno(state->TermiosError);
}

long item;
#define SAFE_LONG_ITEM(obj) \
item = PyLong_AsLong(obj); \
if (item == -1 && PyErr_Occurred()) { \
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
#define SET_FROM_LIST(TYPE, VAR, LIST, N) do { \
PyObject *item = PyList_GET_ITEM(LIST, N); \
long num = PyLong_AsLong(item); \
if (num == -1 && PyErr_Occurred()) { \
return NULL; \
} \
VAR = (TYPE)num; \
} while (0)
SET_FROM_LIST(tcflag_t, mode.c_iflag, term, 0);
SET_FROM_LIST(tcflag_t, mode.c_oflag, term, 1);
SET_FROM_LIST(tcflag_t, mode.c_cflag, term, 2);
SET_FROM_LIST(tcflag_t, mode.c_lflag, term, 3);
SET_FROM_LIST(speed_t, ispeed, term, 4);

Check failure on line 227 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu

‘ispeed’ undeclared (first use in this function)

Check failure on line 227 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

‘ispeed’ undeclared (first use in this function)

Check failure on line 227 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Address sanitizer

‘ispeed’ undeclared (first use in this function)

Check failure on line 227 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.0.11)

‘ispeed’ undeclared (first use in this function)

Check failure on line 227 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

‘ispeed’ undeclared (first use in this function)

Check failure on line 227 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.3)

‘ispeed’ undeclared (first use in this function)
SET_FROM_LIST(speed_t, ospeed, term, 5);

Check failure on line 228 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu

‘ospeed’ undeclared (first use in this function)

Check failure on line 228 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

‘ospeed’ undeclared (first use in this function)

Check failure on line 228 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Address sanitizer

‘ospeed’ undeclared (first use in this function)

Check failure on line 228 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.0.11)

‘ospeed’ undeclared (first use in this function)

Check failure on line 228 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

‘ospeed’ undeclared (first use in this function)

Check failure on line 228 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.3)

‘ospeed’ undeclared (first use in this function)
#undef SET_FROM_LIST

PyObject *cc = PyList_GET_ITEM(term, 6);
if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
Expand All @@ -249,12 +244,13 @@
if (PyBytes_Check(v) && PyBytes_Size(v) == 1)
mode.c_cc[i] = (cc_t) * PyBytes_AsString(v);
else if (PyLong_Check(v)) {
item = PyLong_AsLong(v);

Check failure on line 247 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu

‘item’ undeclared (first use in this function)

Check failure on line 247 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

‘item’ undeclared (first use in this function)

Check failure on line 247 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Address sanitizer

‘item’ undeclared (first use in this function)

Check failure on line 247 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.0.11)

‘item’ undeclared (first use in this function)

Check failure on line 247 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

‘item’ undeclared (first use in this function)

Check failure on line 247 in Modules/termios.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.3)

‘item’ undeclared (first use in this function)
if (item == -1 && PyErr_Occurred()) {
return NULL;
}
mode.c_cc[i] = (cc_t) item;
} else {
}
else {
PyErr_SetString(PyExc_TypeError,
"tcsetattr: elements of attributes must be characters or integers");
return NULL;
Expand Down
Loading