This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eplese
Recipients eplese
Date 2009-11-20.01:24:01
SpamBayes Score 3.0021351e-06
Marked as misclassified No
Message-id <1258680245.88.0.627899346962.issue7365@psf.upfronthosting.co.za>
In-reply-to
Content
Both Linux and Solaris define uid_t and gid_t as unsigned integers.  The
pwd and grp modules cast these to signed long values that are then
converted with PyInt_FromLong.  For large values, greater than 2 ** 32 -
1, the result is correct when Python is compiled as a 64-bit executable,
but is incorrect when compiled as a 32-bit executable.

Similar bugs have been noted in the posix module as reported in #4591.

For example, on OpenSolaris build 127, the 32-bit version of Python
returns a negative uid: pw_uid=-2147483647:

$ file /usr/bin/python2.6
/usr/bin/python2.6:     ELF 32-bit LSB executable 80386 Version 1 [FPU],
dynamically linked, not stripped, no debugging information available

$ /usr/bin/python2.6
Python 2.6.2 (r262, Oct 26 2009, 01:06:14) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import pwd
>>> pwd.getpwnam('test@foo.com')
pwd.struct_passwd(pw_name='test@foo.com', pw_passwd='x',
pw_uid=-2147483647, pw_gid=10000, pw_gecos='Test User', pw_dir='',
pw_shell='')

$ file /usr/bin/amd64/python2.6
/usr/bin/amd64/python2.6:       ELF 64-bit LSB executable AMD64 Version
1 [SSE FXSR FPU], dynamically linked, not stripped, no debugging
information available

$ /usr/bin/amd64/python2.6
Python 2.6.2 (r262, Oct 26 2009, 01:09:04) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import pwd
>>> pwd.getpwnam('test@foo.com')
pwd.struct_passwd(pw_name='test@foo.com', pw_passwd='x',
pw_uid=2147483649, pw_gid=10000, pw_gecos='Test User', pw_dir='',
pw_shell='')

The attached patch against 2.6.4 changes PyInt_FromLong to
PyLong_FromUnsignedLong and changes casts to unsigned long.
History
Date User Action Args
2009-11-20 01:24:06eplesesetrecipients: + eplese
2009-11-20 01:24:05eplesesetmessageid: <1258680245.88.0.627899346962.issue7365@psf.upfronthosting.co.za>
2009-11-20 01:24:04epleselinkissue7365 messages
2009-11-20 01:24:02eplesecreate