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.

classification
Title: grp and pwd should treat uid and gid as unsigned
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: 32-bits unsigned user/group identifier
View: 4591
Assigned To: Nosy List: eplese, sandro.tosi, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2009-11-20 01:24 by eplese, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pwd-grp-unsigned-uid.patch eplese, 2009-11-20 01:24
issue7365_refresh_default.patch sandro.tosi, 2011-03-29 20:08 review
Messages (3)
msg95520 - (view) Author: Ed Plese (eplese) Date: 2009-11-20 01:24
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.
msg132516 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2011-03-29 20:08
I took the freedom to refresh the patch against default (I don't know yet the policies for what to backport and what not), built a debug version of python with the patch applied and run the test suite with no regression.

A test would be nice to be added, but I'm not sure how to do that (is test_grp.py reading local /etc/groups or so?).

I'd be happy another pair of eyes to look at the patch, but it seems worth to be committing it (modulo the backport thing: what lower version should be targetting?).
msg182085 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-02-14 10:51
Fixed by patch for issue4591.
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51614
2013-02-14 10:51:02serhiy.storchakasetstatus: open -> closed

superseder: 32-bits unsigned user/group identifier

nosy: + serhiy.storchaka
messages: + msg182085
resolution: duplicate
stage: patch review -> resolved
2011-06-25 22:39:57terry.reedysetversions: - Python 3.1
2011-03-29 20:08:05sandro.tosisetfiles: + issue7365_refresh_default.patch
versions: + Python 3.3
nosy: + sandro.tosi

messages: + msg132516
2010-07-11 13:56:54brian.curtinsetcomponents: + Extension Modules, - Library (Lib)
2010-07-11 10:53:44BreamoreBoysetstage: patch review
components: + Library (Lib), - Extension Modules
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-11-20 01:24:04eplesecreate