]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #9604: posix.initgroups() encodes the username using the fileystem
authorVictor Stinner <victor.stinner@haypocalc.com>
Sun, 15 Aug 2010 09:22:44 +0000 (09:22 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sun, 15 Aug 2010 09:22:44 +0000 (09:22 +0000)
encoding and surrogateescape error handler. Patch written by David Watson.

Misc/NEWS
Modules/posixmodule.c

index f5cfd384421651af26655a49c005b9f3d3b5656c..a322b3df1612decf04affd588c5ca4c6985bc8ae 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@ Extensions
 Library
 -------
 
+- Issue #9604: posix.initgroups() encodes the username using the fileystem
+  encoding and surrogateescape error handler. Patch written by David Watson.
+
 - Issue #9603: posix.ttyname() and posix.ctermid() decode the terminal name
   using the filesystem encoding and surrogateescape error handler. Patch
   written by David Watson.
index df7cb832579ec9147abf4d32a5167aa514dfaa57..71512896ecd766aaf4d8601ef0912f693d7772f9 100644 (file)
@@ -4249,13 +4249,19 @@ group id.");
 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);