Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61ec5dc

Browse files
author
Victor Stinner
committed
Issue #9604: posix.initgroups() encodes the username using the fileystem
encoding and surrogateescape error handler. Patch written by David Watson.
1 parent 5fe6de8 commit 61ec5dc

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Extensions
8383
Library
8484
-------
8585

86+
- Issue #9604: posix.initgroups() encodes the username using the fileystem
87+
encoding and surrogateescape error handler. Patch written by David Watson.
88+
8689
- Issue #9603: posix.ttyname() and posix.ctermid() decode the terminal name
8790
using the filesystem encoding and surrogateescape error handler. Patch
8891
written by David Watson.

Modules/posixmodule.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4249,13 +4249,19 @@ group id.");
42494249
static PyObject *
42504250
posix_initgroups(PyObject *self, PyObject *args)
42514251
{
4252+
PyObject *oname;
42524253
char *username;
4254+
int res;
42534255
long gid;
42544256

4255-
if (!PyArg_ParseTuple(args, "sl:initgroups", &username, &gid))
4257+
if (!PyArg_ParseTuple(args, "O&l:initgroups",
4258+
PyUnicode_FSConverter, &oname, &gid))
42564259
return NULL;
4260+
username = PyBytes_AS_STRING(oname);
42574261

4258-
if (initgroups(username, (gid_t) gid) == -1)
4262+
res = initgroups(username, (gid_t) gid);
4263+
Py_DECREF(oname);
4264+
if (res == -1)
42594265
return PyErr_SetFromErrno(PyExc_OSError);
42604266

42614267
Py_INCREF(Py_None);

0 commit comments

Comments
 (0)