Skip to content

pwd.getpwnam('nobody') produces incorrect results if sizeof(uid_t) < sizeof(long) #47836

Closed

Description

@mdickinson
BPO 3586
Nosy @gpshead, @mdickinson
Dependencies
  • bpo-5705: os.getpwent returns unsigned 32bit value, os.setuid refuses it
  • 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/gpshead'
    closed_at = <Date 2009-04-06.16:14:30.885>
    created_at = <Date 2008-08-18.10:22:43.946>
    labels = ['extension-modules']
    title = "pwd.getpwnam('nobody') produces incorrect results if sizeof(uid_t) < sizeof(long)"
    updated_at = <Date 2009-04-06.21:43:05.266>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2009-04-06.21:43:05.266>
    actor = 'mark.dickinson'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2009-04-06.16:14:30.885>
    closer = 'gregory.p.smith'
    components = ['Extension Modules']
    creation = <Date 2008-08-18.10:22:43.946>
    creator = 'mark.dickinson'
    dependencies = ['5705']
    files = []
    hgrepos = []
    issue_num = 3586
    keywords = ['64bit']
    message_count = 5.0
    messages = ['71318', '71320', '71350', '85649', '85671']
    nosy_count = 2.0
    nosy_names = ['gregory.p.smith', 'mark.dickinson']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3586'
    versions = ['Python 2.6', 'Python 3.0', 'Python 3.1', 'Python 2.7']

    Activity

    1. mdickinson commented on Aug 18, 2008

      @mdickinson
      MemberAuthor

      On a 64-bit OS X build of Python, built with:

      ./configure --with-universal-archs=64-bit --enable-universalsdk=/ MACOSX_DEPLOYMENT_TARGET=10.5 &&
      make

      I get the following result:

      Python 2.6b2+ (trunk:65805M, Aug 18 2008, 10:59:08) 
      [GCC 4.0.1 (Apple Inc. build 5484)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import pwd
      >>> pwd.getpwnam('nobody')
      pwd.struct_passwd(pw_name='nobody', pw_passwd='*', pw_uid=4294967294, pw_gid=4294967294, 
      pw_gecos='Unprivileged User', pw_dir='/var/empty', pw_shell='/usr/bin/false')

      Here the pw_uid and pw_gid should presumably be -2, not 4294967294. I haven't had time to
      investigate properly, but the problem is almost certainly something to do with the fact that
      sizeof(uid_t) is 4 and sizeof(long) is 8 for this build. (Though interestingly, the configure
      script detects sizeof(long) as 4, which may not be helping matters.)

      This problem is causing test_httpservers to fail on 64-bit OS X.

      System info: it's a MacBook Pro; uname -a gives:
      Darwin Macintosh-3.local 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun 9 19:30:53 PDT 2008; root:xnu-
      1228.5.20~1/RELEASE_I386 i386

    2. added
      extension-modules
      on Aug 18, 2008
    3. mdickinson commented on Aug 18, 2008

      @mdickinson
      MemberAuthor

      It turns out that uid_t (and gid_t) actually *is* an unsigned 32-bit
      integer type on OS X 10.5, so perhaps the pw_uid and pw_gid values are
      correct. So to rephrase: one or both of the following facts might be
      considered bugs:

      (1) On a single machine, the value of pwd.getpwnam('nobody') gives
      different results for 32-bit and 64-bit builds of Python (pw_uid is -2 on
      32-bit, 2**32-2 on 64-bit).

      (2) On a 64-bit OS X build, pwd.getpwnam can produce uids and gids >=
      2**31, but os.setuid and friends don't accept values larger than 2**31-1.
      There's an inconsistency between pwdmodule.c and posixmodule.c: pwdmodule
      casts uids to C longs before returning them, while the posixmodule.c
      functions parse an input uid/gid using the "i" format in PyArg_Parse*.

      It's the latter problem that's causing test_httpservers to fail on 64-bit
      OS X.

    4. mdickinson commented on Aug 18, 2008

      @mdickinson
      MemberAuthor

      bpo-1747858 looks closely related. I propose extending the simple fix
      used there, parsing all uids and gids as longs rather than ints.

    5. gpshead commented on Apr 6, 2009

      @gpshead
      Member

      Fixed via bpo-5705 which I filed not having seen this one.

    6. self-assigned this
      on Apr 6, 2009
    7. mdickinson commented on Apr 6, 2009

      @mdickinson
      MemberAuthor

      I'd completely forgotten about this issue!

      Indeed, test_httpservers now seems to be passing on a 64-bit build
      on my machine. Thank you!

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    extension-modules

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions