@@ -4057,9 +4057,15 @@ Set the current process's user id.");
40574057static PyObject *
40584058posix_setuid (PyObject * self , PyObject * args )
40594059{
4060- int uid ;
4061- if (!PyArg_ParseTuple (args , "i:setuid" , & uid ))
4060+ long uid_arg ;
4061+ uid_t uid ;
4062+ if (!PyArg_ParseTuple (args , "l:setuid" , & uid_arg ))
40624063 return NULL ;
4064+ uid = uid_arg ;
4065+ if (uid != uid_arg ) {
4066+ PyErr_SetString (PyExc_OverflowError , "user id too big" );
4067+ return NULL ;
4068+ }
40634069 if (setuid (uid ) < 0 )
40644070 return posix_error ();
40654071 Py_INCREF (Py_None );
@@ -4076,10 +4082,16 @@ Set the current process's effective user id.");
40764082static PyObject *
40774083posix_seteuid (PyObject * self , PyObject * args )
40784084{
4079- int euid ;
4080- if (!PyArg_ParseTuple (args , "i" , & euid )) {
4085+ long euid_arg ;
4086+ uid_t euid ;
4087+ if (!PyArg_ParseTuple (args , "l" , & euid_arg ))
4088+ return NULL ;
4089+ euid = euid_arg ;
4090+ if (euid != euid_arg ) {
4091+ PyErr_SetString (PyExc_OverflowError , "user id too big" );
40814092 return NULL ;
4082- } else if (seteuid (euid ) < 0 ) {
4093+ }
4094+ if (seteuid (euid ) < 0 ) {
40834095 return posix_error ();
40844096 } else {
40854097 Py_INCREF (Py_None );
@@ -4096,10 +4108,16 @@ Set the current process's effective group id.");
40964108static PyObject *
40974109posix_setegid (PyObject * self , PyObject * args )
40984110{
4099- int egid ;
4100- if (!PyArg_ParseTuple (args , "i" , & egid )) {
4111+ long egid_arg ;
4112+ gid_t egid ;
4113+ if (!PyArg_ParseTuple (args , "l" , & egid_arg ))
4114+ return NULL ;
4115+ egid = egid_arg ;
4116+ if (egid != egid_arg ) {
4117+ PyErr_SetString (PyExc_OverflowError , "group id too big" );
41014118 return NULL ;
4102- } else if (setegid (egid ) < 0 ) {
4119+ }
4120+ if (setegid (egid ) < 0 ) {
41034121 return posix_error ();
41044122 } else {
41054123 Py_INCREF (Py_None );
@@ -4116,10 +4134,17 @@ Set the current process's real and effective user ids.");
41164134static PyObject *
41174135posix_setreuid (PyObject * self , PyObject * args )
41184136{
4119- int ruid , euid ;
4120- if (!PyArg_ParseTuple (args , "ii" , & ruid , & euid )) {
4137+ long ruid_arg , euid_arg ;
4138+ uid_t ruid , euid ;
4139+ if (!PyArg_ParseTuple (args , "ll" , & ruid_arg , & euid_arg ))
41214140 return NULL ;
4122- } else if (setreuid (ruid , euid ) < 0 ) {
4141+ ruid = ruid_arg ;
4142+ euid = euid_arg ;
4143+ if (euid != euid_arg || ruid != ruid_arg ) {
4144+ PyErr_SetString (PyExc_OverflowError , "user id too big" );
4145+ return NULL ;
4146+ }
4147+ if (setreuid (ruid , euid ) < 0 ) {
41234148 return posix_error ();
41244149 } else {
41254150 Py_INCREF (Py_None );
@@ -4136,10 +4161,17 @@ Set the current process's real and effective group ids.");
41364161static PyObject *
41374162posix_setregid (PyObject * self , PyObject * args )
41384163{
4139- int rgid , egid ;
4140- if (!PyArg_ParseTuple (args , "ii" , & rgid , & egid )) {
4164+ long rgid_arg , egid_arg ;
4165+ gid_t rgid , egid ;
4166+ if (!PyArg_ParseTuple (args , "ll" , & rgid_arg , & egid_arg ))
4167+ return NULL ;
4168+ rgid = rgid_arg ;
4169+ egid = egid_arg ;
4170+ if (egid != egid_arg || rgid != rgid_arg ) {
4171+ PyErr_SetString (PyExc_OverflowError , "group id too big" );
41414172 return NULL ;
4142- } else if (setregid (rgid , egid ) < 0 ) {
4173+ }
4174+ if (setregid (rgid , egid ) < 0 ) {
41434175 return posix_error ();
41444176 } else {
41454177 Py_INCREF (Py_None );
@@ -4156,9 +4188,15 @@ Set the current process's group id.");
41564188static PyObject *
41574189posix_setgid (PyObject * self , PyObject * args )
41584190{
4159- int gid ;
4160- if (!PyArg_ParseTuple (args , "i:setgid" , & gid ))
4191+ long gid_arg ;
4192+ gid_t gid ;
4193+ if (!PyArg_ParseTuple (args , "l:setgid" , & gid_arg ))
4194+ return NULL ;
4195+ gid = gid_arg ;
4196+ if (gid != gid_arg ) {
4197+ PyErr_SetString (PyExc_OverflowError , "group id too big" );
41614198 return NULL ;
4199+ }
41624200 if (setgid (gid ) < 0 )
41634201 return posix_error ();
41644202 Py_INCREF (Py_None );
@@ -4205,7 +4243,7 @@ posix_setgroups(PyObject *self, PyObject *groups)
42054243 return NULL ;
42064244 }
42074245 grouplist [i ] = x ;
4208- /* read back the value to see if it fitted in gid_t */
4246+ /* read back to see if it fits in gid_t */
42094247 if (grouplist [i ] != x ) {
42104248 PyErr_SetString (PyExc_TypeError ,
42114249 "group id too big" );
0 commit comments