Skip to content

gh-95380: Removing the 1024 bytes limit in the fcntl_ioctl_impl functions.#95526

Closed
zenbooster wants to merge 11 commits into
python:mainfrom
zenbooster:main
Closed

gh-95380: Removing the 1024 bytes limit in the fcntl_ioctl_impl functions.#95526
zenbooster wants to merge 11 commits into
python:mainfrom
zenbooster:main

Conversation

@zenbooster

@zenbooster zenbooster commented Aug 1, 2022

Copy link
Copy Markdown

zenbooster and others added 9 commits July 29, 2022 15:59
Пулл-реквест pythongh-95429 внёс по сути те же изменения, так что фокусируемся
на отсутствующем там fcntl_ioctl_impl.
Консольная команда, использованная для обновления:

    python Tools/clinic/clinic.py Modules/fcntlmodule.c

Если этого не сделать, автоматическая проверка пулл-реквеста увидит
рассинхронизацию, и у пул-реквеста в статусах будет крестик напротив
"Tests / Check if generated files are up to date".
Remove `fcntl_fcntl_impl` keeping `fcntl_ioctl_impl`
@ghost

ghost commented Aug 1, 2022

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

Comment thread Modules/fcntlmodule.c
if (mutate_arg && (len <= IOCTL_BUFSZ)) {
char *buf = PyBytes_AS_STRING(o);

memcpy(buf, str, len);

Copy link
Copy Markdown
Member

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().

Copy link
Copy Markdown
Member

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.

Comment thread Modules/fcntlmodule.c
}
PyBuffer_Release(&pstr); /* No further access to str below this point */
if (ret < 0) {
Py_DECREF(o);

Copy link
Copy Markdown
Member

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().

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA signed

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

Comment thread Modules/fcntlmodule.c
if (mutate_arg && (len <= IOCTL_BUFSZ)) {
char *buf = PyBytes_AS_STRING(o);

memcpy(buf, str, len);

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants