Merged revisions 78548 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r78548 | gregory.p.smith | 2010-02-28 21:54:14 -0800 (Sun, 28 Feb 2010) | 10 lines

  Merged revisions 78546 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r78546 | gregory.p.smith | 2010-02-28 21:43:43 -0800 (Sun, 28 Feb 2010) | 3 lines

    Fixes issue #7999: os.setreuid() and os.setregid() would refuse to accept
    a -1 parameter on some platforms such as OS X.
  ........
................
This commit is contained in:
Gregory P. Smith 2010-03-01 05:56:53 +00:00
parent 807e98e0af
commit 18ac2b4a71
3 changed files with 25 additions and 6 deletions

View File

@ -717,6 +717,7 @@ if sys.platform != 'win32':
self.assertRaises(os.error, os.setreuid, 0, 0) self.assertRaises(os.error, os.setreuid, 0, 0)
self.assertRaises(OverflowError, os.setreuid, 1<<32, 0) self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
self.assertRaises(OverflowError, os.setreuid, 0, 1<<32) self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
os.setreuid(-1, -1) # Does nothing, but it needs to accept -1
if hasattr(os, 'setregid'): if hasattr(os, 'setregid'):
def test_setregid(self): def test_setregid(self):
@ -724,6 +725,7 @@ if sys.platform != 'win32':
self.assertRaises(os.error, os.setregid, 0, 0) self.assertRaises(os.error, os.setregid, 0, 0)
self.assertRaises(OverflowError, os.setregid, 1<<32, 0) self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
self.assertRaises(OverflowError, os.setregid, 0, 1<<32) 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") @unittest.skipIf(sys.platform == 'darwin', "tests don't apply to OS X")
class Pep383Tests(unittest.TestCase): class Pep383Tests(unittest.TestCase):

View File

@ -351,6 +351,9 @@ Extension Modules
- Expat: Fix DoS via XML document with malformed UTF-8 sequences - Expat: Fix DoS via XML document with malformed UTF-8 sequences
(CVE_2009_3560). (CVE_2009_3560).
- Issue #7999: os.setreuid() and os.setregid() would refuse to accept a -1
parameter on some platforms such as OS X.
Tests Tests
----- -----

View File

@ -4370,9 +4370,16 @@ posix_setreuid (PyObject *self, PyObject *args)
uid_t ruid, euid; uid_t ruid, euid;
if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg)) if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg))
return NULL; return NULL;
ruid = ruid_arg; if (ruid_arg == -1)
euid = euid_arg; ruid = (uid_t)-1; /* let the compiler choose how -1 fits */
if (euid != euid_arg || ruid != ruid_arg) { 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"); PyErr_SetString(PyExc_OverflowError, "user id too big");
return NULL; return NULL;
} }
@ -4397,9 +4404,16 @@ posix_setregid (PyObject *self, PyObject *args)
gid_t rgid, egid; gid_t rgid, egid;
if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg)) if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg))
return NULL; return NULL;
rgid = rgid_arg; if (rgid_arg == -1)
egid = egid_arg; rgid = (gid_t)-1; /* let the compiler choose how -1 fits */
if (egid != egid_arg || rgid != rgid_arg) { 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"); PyErr_SetString(PyExc_OverflowError, "group id too big");
return NULL; return NULL;
} }