-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Fix fcntl module to accept 'unsigned long' type commands for ioctl(2). #69214
Comments
In my current attempt to create a FreeBSD port for python35, I've come across a patch rejection for the fcntlmodule.c for a local port patch we've been carrying since Python 2.6: The original commit log for this change is: ==================================== Fix fcntl module to accept 'unsigned long' type commands for ioctl(2). Although POSIX says the type is 'int', all BSD variants (including Mac OS X) WARNING pid 24509 (python2.6): ioctl sign-extension ioctl ffffffff8004667e ==================================== I'm not sure how this should be fixed upstream, nor clear on how to re-patch it given recent changes to fcntlmodule.c |
You need just replace unsigned_int with unsigned_long in Clinic declaration for fcntl.ioctl in Modules/fcntlmodule.c and regenerate Clinic code (make clinic). |
Thanks for the insight Serhiy. A few questions .. Is clinic code updated based on *.c declarations at build time? If not when/how is the best place/method to run this for our ports/package builds? Does your suggestion to switch unsigned_int to unsigned_long imply that the following lines are no longer necessary?
How do we get something like this fixed upstream for FreeBSD/OSX? If left un-patched, what is the impact on the user/system? Just a warning on console? |
No, the clinic code is not updated at build time. Your should either update clinic code just after patching Modules/fcntlmodule.c (Python 3 is needed), or update clinic code at patch creation time and include changes of generated clinic files in the patch. Generated clinic files contain a code for argument parsing (PyArg_ParseTuple...). I don't know if there is easy way to make this change conditionally for FreeBSD/OSX. The only way that I know is writing custom converters. Perhaps the original commit log is outdated. What was the type of code at the time of this log? Now it is unsigned int and this doesn't make sign extension when casted to unsigned long. While the code parameter is in the range 0..0xffffffff, unpatched code shouldn't have any visible effects. |
Originally the type of the code variable in fcntl_ioctl() was int. In cbad1f5cabb1 it was changed to unsigned int. I guess that the log message that you cited was written before this. |
If necessary, perhaps we could unconditionally change the Python-level argument to unsigned_long, and then add a conditional bit in the C code to convert it to int if appropriate. But I wonder if most of the problem is fixed by bpo-1471 (linked from the commit Serhiy identified). As I see it, your patch should now only be needed to support “code” values outside of the range of unsigned_int, e.g. that require > 32 bits. |
The question is: are ioctl codes outside of the unsigned int range used on BSD family or Mac OS X? |
Maybe bpo-16124 is related; it mentions 64-bit values, but it sounds like an obscure use case. |
Can I take a look at this issue? |
I don't have an authoritative answer for other BSDs or OS X, but for FreeBSD they are not. In addition, we have hidden the warning under a diagnostic option in freebsd/freebsd-src@a90fb6c |
Use an 'unsigned long' instead of an 'unsigned int' for the request parameter of fcntl.ioctl() to support requests larger than UINT_MAX.
Linux manual page of ioctl clearly uses the
Python should use the right type. I wrote PR gh-119498 to fix the request parameter of |
Linux, FreeBSD, macOS uses |
Use an 'unsigned long' instead of an 'unsigned int' for the request parameter of fcntl.ioctl() to support requests larger than UINT_MAX.
Use an 'unsigned long' instead of an 'unsigned int' for the request parameter of fcntl.ioctl() to support requests larger than UINT_MAX. (cherry picked from commit 92fab33) Co-authored-by: Victor Stinner <[email protected]>
Use an 'unsigned long' instead of an 'unsigned int' for the request parameter of fcntl.ioctl() to support requests larger than UINT_MAX. (cherry picked from commit 92fab33)
gh-69214: Fix fcntl.ioctl() request type (GH-119498) Use an 'unsigned long' instead of an 'unsigned int' for the request parameter of fcntl.ioctl() to support requests larger than UINT_MAX. (cherry picked from commit 92fab33) Co-authored-by: Victor Stinner <[email protected]>
…GH-119498) (python#119504)" This reverts commit 0bab0b3.
…GH-119498) (python#119504)" This reverts commit 0bab0b3. The change modified how negative values, like termios.TIOCSWINSZ, was treated and is actually backward incompatible.
…#119498) (python#119505)" This reverts commit 078da88. The change modified how negative values, like termios.TIOCSWINSZ, was treated and is actually backward incompatible.
This change broke test_ioctl on macOS: #119770 So I created two PRs to revert the change in 3.12 and 3.13 branches. |
Thank you Victor for your work! |
I went through FreeBSD issues recently and decided to fix this 9 years old issue. |
Use an 'unsigned long' instead of an 'unsigned int' for the request parameter of fcntl.ioctl() to support requests larger than UINT_MAX.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: