[3.7] bpo-34604: Fix possible mojibake in pwd.getpwnam() and grp.getgrnam() (GH-9098) (GH-9104)

Pass the user/group name as Unicode to the formatting function,
instead of always decoding a bytes string from UTF-8..
(cherry picked from commit 28658485a5)

Co-authored-by: William Grzybowski <wg@FreeBSD.org>
This commit is contained in:
William Grzybowski 2018-09-09 08:27:31 -03:00 committed by Victor Stinner
parent 77b92b15a5
commit 7a633ed79c
3 changed files with 4 additions and 2 deletions

View File

@ -0,0 +1,2 @@
Fix possible mojibake in the error message of `pwd.getpwnam` and
`grp.getgrnam`. Patch by William Grzybowski.

View File

@ -156,7 +156,7 @@ grp_getgrnam_impl(PyObject *module, PyObject *name)
goto out;
if ((p = getgrnam(name_chars)) == NULL) {
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name_chars);
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %S", name);
goto out;
}
retval = mkgrent(p);

View File

@ -163,7 +163,7 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg)
goto out;
if ((p = getpwnam(name)) == NULL) {
PyErr_Format(PyExc_KeyError,
"getpwnam(): name not found: %s", name);
"getpwnam(): name not found: %S", arg);
goto out;
}
retval = mkpwent(p);