]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bug #869197: setgroups rejects long integer argument
authorGeorg Brandl <georg@python.org>
Tue, 22 Nov 2005 19:31:08 +0000 (19:31 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 22 Nov 2005 19:31:08 +0000 (19:31 +0000)
Misc/NEWS
Modules/posixmodule.c

index 8bc7a81ec71451fed3ac2224ca3a04e8d0d77d09..18c078464c013e97434909326260a304816401c8 100644 (file)
--- 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
index 74f09d20684d49c2e5bd26eced9027f9e5e5a11c..a65fb4b162ea15c5e4a3898bdf9bfe5a2a76fec2 100644 (file)
@@ -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);
        }