[Python-checkins] commit of r41515 - in python/branches/release24-maint: Misc Modules

reinhold.birkenfeld@python.org reinhold.birkenfeld at python.org
Tue Nov 22 20:31:14 CET 2005


Author: reinhold.birkenfeld
Date: Tue Nov 22 20:31:08 2005
New Revision: 41515

Modified:
   python/branches/release24-maint/Misc/NEWS
   python/branches/release24-maint/Modules/posixmodule.c
Log:
Bug #869197: setgroups rejects long integer argument




Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS	(original)
+++ python/branches/release24-maint/Misc/NEWS	Tue Nov 22 20:31:08 2005
@@ -29,6 +29,8 @@
 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

Modified: python/branches/release24-maint/Modules/posixmodule.c
==============================================================================
--- python/branches/release24-maint/Modules/posixmodule.c	(original)
+++ python/branches/release24-maint/Modules/posixmodule.c	Tue Nov 22 20:31:08 2005
@@ -4850,13 +4850,38 @@
 		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);
 	}
 


More information about the Python-checkins mailing list