summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2005-11-22 19:31:08 (GMT)
committerGeorg Brandl <georg@python.org>2005-11-22 19:31:08 (GMT)
commitd98dbf9e70d531b44d88e7bb09ca86b74b0017ea (patch)
treeff00b86048fc2a2ffe1c51b377f3fab887421865
parent50541d16481c771af1c70c6eb8137fa4657dcdae (diff)
downloadcpython-d98dbf9e70d531b44d88e7bb09ca86b74b0017ea.zip
cpython-d98dbf9e70d531b44d88e7bb09ca86b74b0017ea.tar.gz
cpython-d98dbf9e70d531b44d88e7bb09ca86b74b0017ea.tar.bz2
Bug #869197: setgroups rejects long integer argument
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/posixmodule.c37
2 files changed, 33 insertions, 6 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 8bc7a81..18c0784 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,8 @@ Core and builtins
Extension Modules
-----------------
+- Bug #869197: os.setgroups rejects long integer arguments
+
- Bug #1344508, Fix UNIX mmap leaking file descriptors
- Patch #1338314, Bug #1336623: fix tarfile so it can extract
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 74f09d2..a65fb4b 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4850,13 +4850,38 @@ posix_setgroups(PyObject *self, PyObject *args)
if (!elem)
return NULL;
if (!PyInt_Check(elem)) {
- PyErr_SetString(PyExc_TypeError,
- "groups must be integers");
- Py_DECREF(elem);
- return NULL;
+ if (!PyLong_Check(elem)) {
+ PyErr_SetString(PyExc_TypeError,
+ "groups must be integers");
+ Py_DECREF(elem);
+ return NULL;
+ } else {
+ unsigned long x = PyLong_AsUnsignedLong(elem);
+ if (PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "group id too big");
+ Py_DECREF(elem);
+ return NULL;
+ }
+ grouplist[i] = x;
+ /* read back the value to see if it fitted in gid_t */
+ if (grouplist[i] != x) {
+ PyErr_SetString(PyExc_TypeError,
+ "group id too big");
+ Py_DECREF(elem);
+ return NULL;
+ }
+ }
+ } else {
+ long x = PyInt_AsLong(elem);
+ grouplist[i] = x;
+ if (grouplist[i] != x) {
+ PyErr_SetString(PyExc_TypeError,
+ "group id too big");
+ Py_DECREF(elem);
+ return NULL;
+ }
}
- /* XXX: check that value fits into gid_t. */
- grouplist[i] = PyInt_AsLong(elem);
Py_DECREF(elem);
}