Skip to content

Commit 92ca030

Browse files
committed
Fix possible mojibake in pwd.getpwnam and grp.getgrnam.
Spotted by: @vstinner
1 parent 23e65b2 commit 92ca030

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
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 `pwd.getpwnam` and `grp.getgrnam`. Patch by William
2+
Grzybowski.

Modules/clinic/pwdmodule.c.h

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/grpmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ grp_getgrnam_impl(PyObject *module, PyObject *name)
245245
PyErr_NoMemory();
246246
}
247247
else {
248-
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name_chars);
248+
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %S", name);
249249
}
250250
goto out;
251251
}

Modules/pwdmodule.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pwd_getpwuid(PyObject *module, PyObject *uidobj)
189189
/*[clinic input]
190190
pwd.getpwnam
191191
192-
arg: unicode
192+
name: unicode
193193
/
194194
195195
Return the password database entry for the given user name.
@@ -198,18 +198,18 @@ See `help(pwd)` for more on password database entries.
198198
[clinic start generated code]*/
199199

200200
static PyObject *
201-
pwd_getpwnam_impl(PyObject *module, PyObject *arg)
202-
/*[clinic end generated code: output=6abeee92430e43d2 input=d5f7e700919b02d3]*/
201+
pwd_getpwnam_impl(PyObject *module, PyObject *name)
202+
/*[clinic end generated code: output=359ce1ddeb7a824f input=a6aeb5e3447fb9e0]*/
203203
{
204-
char *buf = NULL, *buf2 = NULL, *name;
204+
char *buf = NULL, *buf2 = NULL, *name_chars;
205205
int nomem = 0;
206206
struct passwd *p;
207207
PyObject *bytes, *retval = NULL;
208208

209-
if ((bytes = PyUnicode_EncodeFSDefault(arg)) == NULL)
209+
if ((bytes = PyUnicode_EncodeFSDefault(name)) == NULL)
210210
return NULL;
211211
/* check for embedded null bytes */
212-
if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
212+
if (PyBytes_AsStringAndSize(bytes, &name_chars, NULL) == -1)
213213
goto out;
214214
#ifdef HAVE_GETPWNAM_R
215215
Py_BEGIN_ALLOW_THREADS
@@ -229,7 +229,7 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg)
229229
break;
230230
}
231231
buf = buf2;
232-
status = getpwnam_r(name, &pwd, buf, bufsize, &p);
232+
status = getpwnam_r(name_chars, &pwd, buf, bufsize, &p);
233233
if (status != 0) {
234234
p = NULL;
235235
}
@@ -245,15 +245,15 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg)
245245

246246
Py_END_ALLOW_THREADS
247247
#else
248-
p = getpwnam(name);
248+
p = getpwnam(name_chars);
249249
#endif
250250
if (p == NULL) {
251251
if (nomem == 1) {
252252
PyErr_NoMemory();
253253
}
254254
else {
255255
PyErr_Format(PyExc_KeyError,
256-
"getpwnam(): name not found: %s", name);
256+
"getpwnam(): name not found: %S", name);
257257
}
258258
goto out;
259259
}

0 commit comments

Comments
 (0)