From d98dbf9e70d531b44d88e7bb09ca86b74b0017ea Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 22 Nov 2005 19:31:08 +0000 Subject: Bug #869197: setgroups rejects long integer argument --- Misc/NEWS | 2 ++ Modules/posixmodule.c | 37 +++++++++++++++++++++++++++++++------ 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); } -- cgit v0.12