Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-34604: Fix possible mojibake in pwd.getpwnam and grp.getgrnam #9098

Merged
merged 2 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix possible mojibake in the error message of `pwd.getpwnam` and
`grp.getgrnam`. Patch by William Grzybowski.
14 changes: 7 additions & 7 deletions Modules/clinic/pwdmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Modules/grpmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ grp_getgrnam_impl(PyObject *module, PyObject *name)
PyErr_NoMemory();
}
else {
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name_chars);
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %S", name);
}
goto out;
}
Expand Down
18 changes: 9 additions & 9 deletions Modules/pwdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -245,15 +245,15 @@ 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) {
PyErr_NoMemory();
}
else {
PyErr_Format(PyExc_KeyError,
"getpwnam(): name not found: %s", name);
"getpwnam(): name not found: %S", name);
}
goto out;
}
Expand Down