diff -r 0f827775f7b7 Modules/posixmodule.c --- a/Modules/posixmodule.c Wed Feb 13 21:17:13 2013 -0500 +++ b/Modules/posixmodule.c Thu Feb 14 12:59:40 2013 +0200 @@ -407,29 +407,31 @@ { int overflow; long result; - if (PyFloat_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float"); + PyObject *number = PyNumber_Index(obj); + if (number == NULL || !PyLong_Check(number)) { + PyErr_Format(PyExc_TypeError, + "user id must be integer, not %.200s", + obj->ob_type->tp_name); return 0; } - result = PyLong_AsLongAndOverflow(obj, &overflow); + result = PyLong_AsLongAndOverflow(number, &overflow); if (overflow < 0) goto OverflowDown; if (!overflow && result == -1) { /* error or -1 */ if (PyErr_Occurred()) - return 0; + goto Fail; *(uid_t *)p = (uid_t)-1; } else { /* unsigned uid_t */ unsigned long uresult; if (overflow > 0) { - uresult = PyLong_AsUnsignedLong(obj); + uresult = PyLong_AsUnsignedLong(number); if (PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_OverflowError)) goto OverflowUp; - return 0; + goto Fail; } if ((uid_t)uresult == (uid_t)-1) goto OverflowUp; @@ -448,11 +450,15 @@ OverflowDown: PyErr_SetString(PyExc_OverflowError, "user id is less than minimum"); - return 0; + goto Fail; OverflowUp: PyErr_SetString(PyExc_OverflowError, "user id is greater than maximum"); + goto Fail; + +Fail: + Py_DECREF(number); return 0; } @@ -461,29 +467,31 @@ { int overflow; long result; - if (PyFloat_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float"); + PyObject *number = PyNumber_Index(obj); + if (number == NULL || !PyLong_Check(number)) { + PyErr_Format(PyExc_TypeError, + "group id must be integer, not %.200s", + obj->ob_type->tp_name); return 0; } - result = PyLong_AsLongAndOverflow(obj, &overflow); + result = PyLong_AsLongAndOverflow(number, &overflow); if (overflow < 0) goto OverflowDown; if (!overflow && result == -1) { /* error or -1 */ if (PyErr_Occurred()) - return 0; + goto Fail; *(gid_t *)p = (gid_t)-1; } else { /* unsigned gid_t */ unsigned long uresult; if (overflow > 0) { - uresult = PyLong_AsUnsignedLong(obj); + uresult = PyLong_AsUnsignedLong(number); if (PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_OverflowError)) goto OverflowUp; - return 0; + goto Fail; } if ((gid_t)uresult == (gid_t)-1) goto OverflowUp; @@ -502,11 +510,15 @@ OverflowDown: PyErr_SetString(PyExc_OverflowError, "group id is less than minimum"); - return 0; + goto Fail; OverflowUp: PyErr_SetString(PyExc_OverflowError, "group id is greater than maximum"); + goto Fail; + +Fail: + Py_DECREF(number); return 0; } #endif /* MS_WINDOWS */