diff options
author | Georg Brandl <georg@python.org> | 2005-11-22 19:31:08 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2005-11-22 19:31:08 (GMT) |
commit | d98dbf9e70d531b44d88e7bb09ca86b74b0017ea (patch) | |
tree | ff00b86048fc2a2ffe1c51b377f3fab887421865 | |
parent | 50541d16481c771af1c70c6eb8137fa4657dcdae (diff) | |
download | cpython-d98dbf9e70d531b44d88e7bb09ca86b74b0017ea.zip cpython-d98dbf9e70d531b44d88e7bb09ca86b74b0017ea.tar.gz cpython-d98dbf9e70d531b44d88e7bb09ca86b74b0017ea.tar.bz2 |
Bug #869197: setgroups rejects long integer argument
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/posixmodule.c | 37 |
2 files changed, 33 insertions, 6 deletions
@@ -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); } |