summaryrefslogtreecommitdiffstats
path: root/Modules/pwdmodule.c
diff options
context:
space:
mode:
authorWilliam Grzybowski <wg@FreeBSD.org>2018-09-07 17:10:39 (GMT)
committerVictor Stinner <vstinner@redhat.com>2018-09-07 17:10:39 (GMT)
commit28658485a54ad5f9df52ecc12d9046269f1654ec (patch)
tree37481555ef2aabc3af2c325ef4b6c6c65e2662ef /Modules/pwdmodule.c
parent7e610bcdf128f61b925654e4fa80fbac83537d0e (diff)
downloadcpython-28658485a54ad5f9df52ecc12d9046269f1654ec.zip
cpython-28658485a54ad5f9df52ecc12d9046269f1654ec.tar.gz
cpython-28658485a54ad5f9df52ecc12d9046269f1654ec.tar.bz2
bpo-34604: Fix possible mojibake in pwd.getpwnam() and grp.getgrnam() (GH-9098)
Pass the user/group name as Unicode to the formatting function, instead of always decoding a bytes string from UTF-8.
Diffstat (limited to 'Modules/pwdmodule.c')
-rw-r--r--Modules/pwdmodule.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index 36192a5..d15286d 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -189,7 +189,7 @@ pwd_getpwuid(PyObject *module, PyObject *uidobj)
/*[clinic input]
pwd.getpwnam
- arg: unicode
+ name: unicode
/
Return the password database entry for the given user name.
@@ -198,18 +198,18 @@ See `help(pwd)` for more on password database entries.
[clinic start generated code]*/
static PyObject *
-pwd_getpwnam_impl(PyObject *module, PyObject *arg)
-/*[clinic end generated code: output=6abeee92430e43d2 input=d5f7e700919b02d3]*/
+pwd_getpwnam_impl(PyObject *module, PyObject *name)
+/*[clinic end generated code: output=359ce1ddeb7a824f input=a6aeb5e3447fb9e0]*/
{
- char *buf = NULL, *buf2 = NULL, *name;
+ char *buf = NULL, *buf2 = NULL, *name_chars;
int nomem = 0;
struct passwd *p;
PyObject *bytes, *retval = NULL;
- if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
+ if ((bytes = PyUnicode_EncodeFSDefault(name)) == NULL)
return NULL;
/* check for embedded null bytes */
- if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
+ if (PyBytes_AsStringAndSize(bytes, &name_chars, NULL) == -1)
goto out;
#ifdef HAVE_GETPWNAM_R
Py_BEGIN_ALLOW_THREADS
@@ -229,7 +229,7 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg)
break;
}
buf = buf2;
- status = getpwnam_r(name, &pwd, buf, bufsize, &p);
+ status = getpwnam_r(name_chars, &pwd, buf, bufsize, &p);
if (status != 0) {
p = NULL;
}
@@ -245,7 +245,7 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg)
Py_END_ALLOW_THREADS
#else
- p = getpwnam(name);
+ p = getpwnam(name_chars);
#endif
if (p == NULL) {
if (nomem == 1) {
@@ -253,7 +253,7 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg)
}
else {
PyErr_Format(PyExc_KeyError,
- "getpwnam(): name not found: %s", name);
+ "getpwnam(): name not found: %S", name);
}
goto out;
}