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
mknod devices can be >32 bits #67287
Comments
Dan MacDonald told me that "os.mknod()" should accept devices >32 bits. I wrote this code in linux 64 bits: """
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main(void) {
printf("%d", sizeof(dev_t));
return 0;
}
""" The result of running this is "8". We need a long long. I did this change in Python 2.7 branch: """
diff -r f00412d32b41 Modules/posixmodule.c
--- a/Modules/posixmodule.c Sat Dec 20 13:41:14 2014 -0600
+++ b/Modules/posixmodule.c Sun Dec 21 23:30:00 2014 +0100
@@ -7009,9 +7009,9 @@
{
char *filename;
int mode = 0600;
- int device = 0;
+ long long device = 0;
int res;
- if (!PyArg_ParseTuple(args, "s|ii:mknod", &filename, &mode, &device))
+ if (!PyArg_ParseTuple(args, "s|iL:mknod", &filename, &mode, &device))
return NULL;
Py_BEGIN_ALLOW_THREADS
res = mknod(filename, mode, device);
""" Looks like this patch is trivial. Please, comment. |
This is not so easy as look at first glance. PY_LONG_LONG should be used instead of long long. And as far as this type is optional, its use should be conditional if HAVE_LONG_LONG is defined. May be needed complex converter like _Py_Uid_Converter because dev_t on Linux is 64-bit unsigned int and can not fit in the range of 64-bit signed int. The code for 3.x should be even more complex due to using Argument Clinic. |
Serhiy, could you consider to create a patch for 2.7 and 3.4?. I am not familiar with the details of Argument Clinic. |
Here is a patch against 3.5. Unsigned bitwise int converter is used for dev_t because dev_t can be unsigned (and it is on Linux). This is not ideal solution, there is no overflow check, but at least it should work for correct code. |
As pointed by Antoine there are other affected functions. Updated patch fixes converting of arguments or results in makedev(), major() and minor(). |
And here are patches for 2.7 and 3.4 (unfortunately none of patches is applied |
New changeset 7ee09e2fec13 by Serhiy Storchaka in branch '2.7': New changeset 18703ffea2b3 by Serhiy Storchaka in branch '3.4': New changeset fe0fddd6fd21 by Serhiy Storchaka in branch 'default': |
Committed to 2.7 with small change: stat() and makedev() should return int instead of long if possible. |
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:
The text was updated successfully, but these errors were encountered: