Author: Andrews Medina <andrewsmed...@gmail.com> Branch: stdlib-2.7.4-pwd-fix Changeset: r66080:210278811677 Date: 2013-08-11 23:23 -0300 http://bitbucket.org/pypy/pypy/changeset/210278811677/
Log: improved the uid range check diff --git a/pypy/module/pwd/interp_pwd.py b/pypy/module/pwd/interp_pwd.py --- a/pypy/module/pwd/interp_pwd.py +++ b/pypy/module/pwd/interp_pwd.py @@ -5,6 +5,19 @@ from pypy.interpreter.error import OperationError, operationerrfmt from rpython.rlib.rarithmetic import intmask +import sys + + +if sys.maxint == 2147483647: + def check_uid_range(space, num): + pass +else: + def check_uid_range(space, num): + if num < -(1<<31) or num >= (1<<32): + msg = "getpwuid(): uid not found" + raise OperationError(space.w_KeyError, space.wrap(msg)) + + eci = ExternalCompilationInfo( includes=['pwd.h'] ) @@ -52,6 +65,7 @@ ]) return space.call_function(w_passwd_struct, w_tuple) + def getpwuid(space, w_uid): """ getpwuid(uid) -> (pw_name,pw_passwd,pw_uid, @@ -59,12 +73,14 @@ Return the password database entry for the given numeric user ID. See pwd.__doc__ for more on password database entries. """ - import sys - if space.is_true(space.or_(space.gt(w_uid, space.wrap(sys.maxint)), - space.lt(w_uid, space.wrap(-sys.maxint - 1)))): - msg = "getpwuid(): uid not found" - raise OperationError(space.w_KeyError, space.wrap(msg)) - uid = space.int_w(w_uid) + try: + uid = space.int_w(w_uid) + except OperationError, e: + if e.match(space, space.w_OverflowError): + msg = "getpwuid(): uid not found" + raise OperationError(space.w_KeyError, space.wrap(msg)) + raise + check_uid_range(space, uid) pw = c_getpwuid(uid) if not pw: raise operationerrfmt(space.w_KeyError, diff --git a/pypy/module/pwd/test/test_pwd.py b/pypy/module/pwd/test/test_pwd.py --- a/pypy/module/pwd/test/test_pwd.py +++ b/pypy/module/pwd/test/test_pwd.py @@ -25,6 +25,8 @@ # should be out of uid_t range raises(KeyError, pwd.getpwuid, 2**128) raises(KeyError, pwd.getpwuid, -2**128) + raises(KeyError, pwd.getpwuid, (1<<32)) + raises(KeyError, pwd.getpwuid, -(1<<32)) def test_getpwnam(self): import pwd _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit