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

index 77e280dcbe79cd74d6284fb314ac7cd53c9d04d8..955015602ec40aab12d78b868f7aef4a766fcf1b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -181,6 +181,8 @@ Core and builtins
 Extension Modules
 -----------------
 
+- Bug #869197: os.setgroups rejects long integer arguments
+
 - Bug #1346533, select.poll() doesn't raise an error if timeout > sys.maxint
 
 - Bug #1344508, Fix UNIX mmap leaking file descriptors
index 6f771595feae01b2440d0a4194620c57b56b2426..a08058f6f1f58c5646c4cf134e1eb2faf7425cfc 100644 (file)
@@ -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);
        }