summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2005-11-22 19:30:31 (GMT)
committerGeorg Brandl <georg@python.org>2005-11-22 19:30:31 (GMT)
commita13c2446dc4620f806ea5155289c36ab91cad484 (patch)
treed3d4c289c4be411d5e5ba14942f2745fd01066ae /Modules/posixmodule.c
parentf96f5f5bbec6de78183b87da431672b8f850d73f (diff)
downloadcpython-a13c2446dc4620f806ea5155289c36ab91cad484.zip
cpython-a13c2446dc4620f806ea5155289c36ab91cad484.tar.gz
cpython-a13c2446dc4620f806ea5155289c36ab91cad484.tar.bz2
Bug #869197: setgroups rejects long integer argument
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 6f77159..a08058f 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4912,13 +4912,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);
}