From: Georg Brandl Date: Tue, 22 Nov 2005 19:31:08 +0000 (+0000) Subject: Bug #869197: setgroups rejects long integer argument X-Git-Tag: v2.4.3c1~206 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d98dbf9e70d531b44d88e7bb09ca86b74b0017ea;p=thirdparty%2FPython%2Fcpython.git Bug #869197: setgroups rejects long integer argument --- diff --git a/Misc/NEWS b/Misc/NEWS index 8bc7a81ec714..18c078464c01 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 74f09d20684d..a65fb4b162ea 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); }