]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.6] bpo-34604: Fix possible mojibake in pwd.getpwnam() and grp.getgrnam() (GH-9098...
authorWilliam Grzybowski <wg@FreeBSD.org>
Sun, 9 Sep 2018 11:26:48 +0000 (08:26 -0300)
committerVictor Stinner <vstinner@redhat.com>
Sun, 9 Sep 2018 11:26:48 +0000 (13:26 +0200)
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 28658485a54ad5f9df52ecc12d9046269f1654ec)

Co-authored-by: William Grzybowski <wg@FreeBSD.org>
Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst [new file with mode: 0644]
Modules/grpmodule.c
Modules/pwdmodule.c

diff --git a/Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst b/Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst
new file mode 100644 (file)
index 0000000..562a691
--- /dev/null
@@ -0,0 +1,2 @@
+Fix possible mojibake in the error message of `pwd.getpwnam` and
+`grp.getgrnam`. Patch by William Grzybowski.
index f577fd3ab4ec3baeabcd09499d62229d457ad273..43e45ef7aad5c1e4bd6786bf608735888e1e81e5 100644 (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);
index bbef2de9c52253287f7dc068d798d33044f674c8..21c2b546f6ddaf68ede187f6b756ebaceb153dca 100644 (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);