-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-95380: Removing the 1024 bytes limit in the fcntl_ioctl_impl functions. #95526
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
Conversation
…ва разных варианта исправления.
…pl убрал buf[len] = '\0';
Пулл-реквест pythongh-95429 внёс по сути те же изменения, так что фокусируемся на отсутствующем там fcntl_ioctl_impl.
Консольная команда, использованная для обновления: python Tools/clinic/clinic.py Modules/fcntlmodule.c Если этого не сделать, автоматическая проверка пулл-реквеста увидит рассинхронизацию, и у пул-реквеста в статусах будет крестик напротив "Tests / Check if generated files are up to date".
python#95380 (comment) fcntl_ioctl_impl: add Py_DECREF.
Remove `fcntl_fcntl_impl` keeping `fcntl_ioctl_impl`
if (mutate_arg && (len <= IOCTL_BUFSZ)) { | ||
char *buf = PyBytes_AS_STRING(o); | ||
|
||
memcpy(buf, str, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simply pass it to PyBytes_FromStringAndSize()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On other hand, using NULL is necessary to prevent caching of newly created bytes object.
memcpy(str, buf, len); | ||
} | ||
PyBuffer_Release(&pstr); /* No further access to str below this point */ | ||
if (ret < 0) { | ||
Py_DECREF(o); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyBuffer_Release()
and Py_DECREF()
can modify errno
. You should save its value after ioctl()
call and restore it just before PyErr_SetFromErrno()
.
The following commit authors need to sign the Contributor License Agreement: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR was not active for a long time, I created an alternative PR #132907, which keeps using a 1024 bytes buffer for small arguments. This is safer in case of buffer overflow.
if (mutate_arg && (len <= IOCTL_BUFSZ)) { | ||
char *buf = PyBytes_AS_STRING(o); | ||
|
||
memcpy(buf, str, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On other hand, using NULL is necessary to prevent caching of newly created bytes object.
Also decrefs added.