New GitHub issue #110260 from sobolevn:<br>
<hr>
<pre>
# Bug report
There are multiple cases where `PyList_SetItem` does not check for `-1` in `termios` module. We need to fix this. There are two options to fix this:
- `< 0` check
- `PyList_SET_ITEM` usage
There are two possible errors that `PyList_SetItem` can produce:
```c
if (!PyList_Check(op)) {
Py_XDECREF(newitem);
PyErr_BadInternalCall();
return -1;
}
if (!valid_index(i, Py_SIZE(op))) {
Py_XDECREF(newitem);
PyErr_SetString(PyExc_IndexError,
"list assignment index out of range");
return -1;
}
```
Each case needs an explanation.
https://github.com/python/cpython/blob/8c071373f12f325c54591fe990ec026184e48f8f/Modules/termios.c#L116-L124
Here `cc` is always a `list` and `i` goes from `0` to some other `int` value by `i++`, it is safe to use `PyList_SET_ITEM`.
https://github.com/python/cpython/blob/8c071373f12f325c54591fe990ec026184e48f8f/Modules/termios.c#L129-L137
Here `cc` is a list, but `VMIN` and `VTIME` are 3rd party constants from `termios.h`. I guess it is safer to use explicit error check.
https://github.com/python/cpython/blob/8c071373f12f325c54591fe990ec026184e48f8f/Modules/termios.c#L140-L153
Here we need to check for possibel `PyLong_FromLong` error, but we can use `PyList_SET_ITEM`.
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/110260">View on GitHub</a>
<p>Labels: type-bug, extension-modules</p>
<p>Assignee: sobolevn</p>