diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 9846d923f59..95c7747152a 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -738,6 +738,7 @@ if sys.platform != 'win32': self.assertRaises(os.error, os.setreuid, 0, 0) self.assertRaises(OverflowError, os.setreuid, 1<<32, 0) self.assertRaises(OverflowError, os.setreuid, 0, 1<<32) + os.setreuid(-1, -1) # Does nothing, but it needs to accept -1 if hasattr(os, 'setregid'): def test_setregid(self): @@ -745,6 +746,7 @@ if sys.platform != 'win32': self.assertRaises(os.error, os.setregid, 0, 0) self.assertRaises(OverflowError, os.setregid, 1<<32, 0) self.assertRaises(OverflowError, os.setregid, 0, 1<<32) + os.setregid(-1, -1) # Does nothing, but it needs to accept -1 @unittest.skipIf(sys.platform == 'darwin', "tests don't apply to OS X") class Pep383Tests(unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS index c529e18041d..fda73e3bc8e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -751,6 +751,9 @@ Extension Modules - Expat: Fix DoS via XML document with malformed UTF-8 sequences (CVE_2009_3560). +- Issue #7999: os.setreuid() and os.setregid() would refuse to accept a -1 + parameter on some platforms such as OS X. + Build ----- diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 96d8d4d55dc..8e3f4c0d83f 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4288,9 +4288,16 @@ posix_setreuid (PyObject *self, PyObject *args) uid_t ruid, euid; if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg)) return NULL; - ruid = ruid_arg; - euid = euid_arg; - if (euid != euid_arg || ruid != ruid_arg) { + if (ruid_arg == -1) + ruid = (uid_t)-1; /* let the compiler choose how -1 fits */ + else + ruid = ruid_arg; /* otherwise, assign from our long */ + if (euid_arg == -1) + euid = (uid_t)-1; + else + euid = euid_arg; + if ((euid_arg != -1 && euid != euid_arg) || + (ruid_arg != -1 && ruid != ruid_arg)) { PyErr_SetString(PyExc_OverflowError, "user id too big"); return NULL; } @@ -4315,9 +4322,16 @@ posix_setregid (PyObject *self, PyObject *args) gid_t rgid, egid; if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg)) return NULL; - rgid = rgid_arg; - egid = egid_arg; - if (egid != egid_arg || rgid != rgid_arg) { + if (rgid_arg == -1) + rgid = (gid_t)-1; /* let the compiler choose how -1 fits */ + else + rgid = rgid_arg; /* otherwise, assign from our long */ + if (egid_arg == -1) + egid = (gid_t)-1; + else + egid = egid_arg; + if ((egid_arg != -1 && egid != egid_arg) || + (rgid_arg != -1 && rgid != rgid_arg)) { PyErr_SetString(PyExc_OverflowError, "group id too big"); return NULL; }