Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2865848

Browse files
william-grvstinner
authored andcommitted
bpo-34604: Fix possible mojibake in pwd.getpwnam() and grp.getgrnam() (GH-9098)
Pass the user/group name as Unicode to the formatting function,instead of always decoding a bytes string from UTF-8.
1 parent7e610bc commit2865848

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 the error message of `pwd.getpwnam` and
2+
`grp.getgrnam`. Patch by William Grzybowski.

‎Modules/clinic/pwdmodule.c.h‎

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing 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
gotoout;
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
staticPyObject*
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
intnomem=0;
206206
structpasswd*p;
207207
PyObject*bytes,*retval=NULL;
208208

209-
if ((bytes=PyUnicode_EncodeFSDefault(arg))==NULL)
209+
if ((bytes=PyUnicode_EncodeFSDefault(name))==NULL)
210210
returnNULL;
211211
/* check for embedded null bytes */
212-
if (PyBytes_AsStringAndSize(bytes,&name,NULL)==-1)
212+
if (PyBytes_AsStringAndSize(bytes,&name_chars,NULL)==-1)
213213
gotoout;
214214
#ifdefHAVE_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
gotoout;
259259
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp