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: setregid does not work with -1 as argument
Type: Stage:
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: Alexander.Belopolsky, Ondrej.Palkovsky, gregory.p.smith, ned.deily
Priority: normal Keywords:

Created on 2010-02-23 09:58 by Ondrej.Palkovsky, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg99906 - (view) Author: Ondrej Palkovsky (Ondrej.Palkovsky) Date: 2010-02-23 09:58
There is a check on correctness of the argument for setregid in posixmodule.c:

	if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg))
		return NULL;
	rgid = rgid_arg;
	egid = egid_arg;
	if (egid != egid_arg || rgid != rgid_arg) {
		PyErr_SetString(PyExc_OverflowError, "group id too big");
		return NULL;
	}

However, the egid_t(egid) is unsigned 32-bit, while egid_arg is signed 64-bit, so after this comparison the result "overflows".
msg100130 - (view) Author: Alexander Belopolsky (Alexander.Belopolsky) Date: 2010-02-26 00:44
I reproduced this bug on OSX 10.6:

>>> os.setregid(-1,-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: group id too big

Since -1 has special meaning as an argument to POSIX setregid(rgid, egid),

"""
If rgid is -1, the real group ID shall not be changed; if egid is -1, the effective group ID shall not be changed.
"""

I think passing -1 to os. setregid() should be supported.

Meanwhile the following work-around works for me on OSX, but may not work on other platforms:

>>> os.setregid(2**32-1,2**32-1)
msg100138 - (view) Author: Alexander Belopolsky (Alexander.Belopolsky) Date: 2010-02-26 06:20
Question:  If we allow -1 to be passed to os.setregid as (gid_t)-1, what should passing 2**32-1 mean? Two possibilities are: treat it same way as -1 or raise a "gid is to big" error.
msg100248 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2010-03-01 05:57
fixed in trunk in r78546 & backported to 2.6 and 3.1.
msg100328 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-03-03 02:41
Apparently there is a side effect on OS X 10.6 of setting to -1.  See Issue8045.
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52247
2010-03-03 02:41:14ned.deilysetnosy: + ned.deily
messages: + msg100328
2010-03-01 05:57:20gregory.p.smithsetstatus: open -> closed
resolution: fixed
messages: + msg100248
2010-03-01 05:31:04gregory.p.smithsetpriority: normal
assignee: gregory.p.smith

nosy: + gregory.p.smith
versions: + Python 3.1, Python 2.7, Python 3.2
2010-02-26 06:20:29Alexander.Belopolskysetmessages: + msg100138
2010-02-26 00:44:02Alexander.Belopolskysetnosy: + Alexander.Belopolsky
messages: + msg100130
2010-02-23 09:58:04Ondrej.Palkovskycreate