Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18ac2b4

Browse files
committed
Merged revisions 78548 via svnmerge from
svn+ssh://[email protected]/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://[email protected]/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. ........ ................
1 parent 807e98e commit 18ac2b4

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

Lib/test/test_os.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,15 @@ def test_setreuid(self):
717717
self.assertRaises(os.error, os.setreuid, 0, 0)
718718
self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
719719
self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
720+
os.setreuid(-1, -1) # Does nothing, but it needs to accept -1
720721

721722
if hasattr(os, 'setregid'):
722723
def test_setregid(self):
723724
if os.getuid() != 0:
724725
self.assertRaises(os.error, os.setregid, 0, 0)
725726
self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
726727
self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
728+
os.setregid(-1, -1) # Does nothing, but it needs to accept -1
727729

728730
@unittest.skipIf(sys.platform == 'darwin', "tests don't apply to OS X")
729731
class Pep383Tests(unittest.TestCase):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ Extension Modules
351351
- Expat: Fix DoS via XML document with malformed UTF-8 sequences
352352
(CVE_2009_3560).
353353

354+
- Issue #7999: os.setreuid() and os.setregid() would refuse to accept a -1
355+
parameter on some platforms such as OS X.
356+
354357
Tests
355358
-----
356359

Modules/posixmodule.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,9 +4370,16 @@ posix_setreuid (PyObject *self, PyObject *args)
43704370
uid_t ruid, euid;
43714371
if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg))
43724372
return NULL;
4373-
ruid = ruid_arg;
4374-
euid = euid_arg;
4375-
if (euid != euid_arg || ruid != ruid_arg) {
4373+
if (ruid_arg == -1)
4374+
ruid = (uid_t)-1; /* let the compiler choose how -1 fits */
4375+
else
4376+
ruid = ruid_arg; /* otherwise, assign from our long */
4377+
if (euid_arg == -1)
4378+
euid = (uid_t)-1;
4379+
else
4380+
euid = euid_arg;
4381+
if ((euid_arg != -1 && euid != euid_arg) ||
4382+
(ruid_arg != -1 && ruid != ruid_arg)) {
43764383
PyErr_SetString(PyExc_OverflowError, "user id too big");
43774384
return NULL;
43784385
}
@@ -4397,9 +4404,16 @@ posix_setregid (PyObject *self, PyObject *args)
43974404
gid_t rgid, egid;
43984405
if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg))
43994406
return NULL;
4400-
rgid = rgid_arg;
4401-
egid = egid_arg;
4402-
if (egid != egid_arg || rgid != rgid_arg) {
4407+
if (rgid_arg == -1)
4408+
rgid = (gid_t)-1; /* let the compiler choose how -1 fits */
4409+
else
4410+
rgid = rgid_arg; /* otherwise, assign from our long */
4411+
if (egid_arg == -1)
4412+
egid = (gid_t)-1;
4413+
else
4414+
egid = egid_arg;
4415+
if ((egid_arg != -1 && egid != egid_arg) ||
4416+
(rgid_arg != -1 && rgid != rgid_arg)) {
44034417
PyErr_SetString(PyExc_OverflowError, "group id too big");
44044418
return NULL;
44054419
}

0 commit comments

Comments
 (0)