Issue #9604: posix.initgroups() encodes the username using the fileystem
encoding and surrogateescape error handler. Patch written by David Watson.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index df7cb83..7151289 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4249,13 +4249,19 @@
static PyObject *
posix_initgroups(PyObject *self, PyObject *args)
{
+ PyObject *oname;
char *username;
+ int res;
long gid;
- if (!PyArg_ParseTuple(args, "sl:initgroups", &username, &gid))
+ if (!PyArg_ParseTuple(args, "O&l:initgroups",
+ PyUnicode_FSConverter, &oname, &gid))
return NULL;
+ username = PyBytes_AS_STRING(oname);
- if (initgroups(username, (gid_t) gid) == -1)
+ res = initgroups(username, (gid_t) gid);
+ Py_DECREF(oname);
+ if (res == -1)
return PyErr_SetFromErrno(PyExc_OSError);
Py_INCREF(Py_None);