Skip to content

Commit 1bcd891

Browse files
william-grvstinner
authored andcommitted
[3.6] bpo-34604: Fix possible mojibake in pwd.getpwnam() and grp.getgrnam() (GH-9098) (GH-9105)
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 2865848) Co-authored-by: William Grzybowski <[email protected]>
1 parent 3b36642 commit 1bcd891

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible mojibake in the error message of `pwd.getpwnam` and
2+
`grp.getgrnam`. Patch by William Grzybowski.

Modules/grpmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ grp_getgrnam_impl(PyObject *module, PyObject *name)
156156
goto out;
157157

158158
if ((p = getgrnam(name_chars)) == NULL) {
159-
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name_chars);
159+
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %S", name);
160160
goto out;
161161
}
162162
retval = mkgrent(p);

Modules/pwdmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg)
163163
goto out;
164164
if ((p = getpwnam(name)) == NULL) {
165165
PyErr_Format(PyExc_KeyError,
166-
"getpwnam(): name not found: %s", name);
166+
"getpwnam(): name not found: %S", arg);
167167
goto out;
168168
}
169169
retval = mkpwent(p);

0 commit comments

Comments
 (0)