Navigation Menu

Skip to content
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

Closed
jcea opened this issue Dec 21, 2014 · 8 comments
Closed

mknod devices can be >32 bits #67287

jcea opened this issue Dec 21, 2014 · 8 comments
Assignees
Labels
easy extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@jcea
Copy link
Member

jcea commented Dec 21, 2014

BPO 23098
Nosy @jcea, @serhiy-storchaka
Files
  • posix_dev_t_converter-3.5.patch
  • posix_dev_t_converter-3.5_2.patch
  • posix_dev_t_converter-2.7.patch
  • posix_dev_t_converter-3.4.patch
  • 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:

    assignee = 'https://github.com/jcea'
    closed_at = <Date 2015-01-18.09:47:58.037>
    created_at = <Date 2014-12-21.22:36:24.874>
    labels = ['extension-modules', 'easy', 'type-bug']
    title = 'mknod devices can be >32 bits'
    updated_at = <Date 2015-01-18.09:47:58.036>
    user = 'https://github.com/jcea'

    bugs.python.org fields:

    activity = <Date 2015-01-18.09:47:58.036>
    actor = 'serhiy.storchaka'
    assignee = 'jcea'
    closed = True
    closed_date = <Date 2015-01-18.09:47:58.037>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2014-12-21.22:36:24.874>
    creator = 'jcea'
    dependencies = []
    files = ['37526', '37527', '37532', '37533']
    hgrepos = []
    issue_num = 23098
    keywords = ['patch', 'easy']
    message_count = 8.0
    messages = ['233004', '233015', '233019', '233022', '233026', '233037', '234229', '234232']
    nosy_count = 3.0
    nosy_names = ['jcea', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23098'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @jcea
    Copy link
    Member Author

    jcea commented Dec 21, 2014

    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.

    @jcea jcea self-assigned this Dec 21, 2014
    @jcea jcea added the easy label Dec 21, 2014
    @serhiy-storchaka
    Copy link
    Member

    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-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Dec 22, 2014
    @jcea
    Copy link
    Member Author

    jcea commented Dec 22, 2014

    Serhiy, could you consider to create a patch for 2.7 and 3.4?. I am not familiar with the details of Argument Clinic.

    @serhiy-storchaka
    Copy link
    Member

    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.

    @serhiy-storchaka
    Copy link
    Member

    As pointed by Antoine there are other affected functions. Updated patch fixes converting of arguments or results in makedev(), major() and minor().

    @serhiy-storchaka
    Copy link
    Member

    And here are patches for 2.7 and 3.4 (unfortunately none of patches is applied
    clear to other version).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 18, 2015

    New changeset 7ee09e2fec13 by Serhiy Storchaka in branch '2.7':
    Issue bpo-23098: 64-bit dev_t is now supported in the os module.
    https://hg.python.org/cpython/rev/7ee09e2fec13

    New changeset 18703ffea2b3 by Serhiy Storchaka in branch '3.4':
    Issue bpo-23098: 64-bit dev_t is now supported in the os module.
    https://hg.python.org/cpython/rev/18703ffea2b3

    New changeset fe0fddd6fd21 by Serhiy Storchaka in branch 'default':
    Issue bpo-23098: 64-bit dev_t is now supported in the os module.
    https://hg.python.org/cpython/rev/fe0fddd6fd21

    @serhiy-storchaka
    Copy link
    Member

    Committed to 2.7 with small change: stat() and makedev() should return int instead of long if possible.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants