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

Commit458e330

Browse files
authored
gh-127081: lock non-re-entrant*pwent calls in free-threading (#132748)
1 parent2602d8a commit458e330

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix libc thread safety issues with:mod:`pwd` by locking access to
2+
``getpwall``.

‎Modules/pwdmodule.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,33 @@ pwd_getpwall_impl(PyObject *module)
301301
structpasswd*p;
302302
if ((d=PyList_New(0))==NULL)
303303
returnNULL;
304+
305+
#ifdefPy_GIL_DISABLED
306+
staticPyMutexgetpwall_mutex= {0};
307+
PyMutex_Lock(&getpwall_mutex);
308+
#endif
309+
intfailure=0;
310+
PyObject*v=NULL;
304311
setpwent();
305312
while ((p=getpwent())!=NULL) {
306-
PyObject*v=mkpwent(module,p);
313+
v=mkpwent(module,p);
307314
if (v==NULL||PyList_Append(d,v)!=0) {
308-
Py_XDECREF(v);
309-
Py_DECREF(d);
310-
endpwent();
311-
returnNULL;
315+
/* NOTE: cannot dec-ref here, while holding the mutex. */
316+
failure=1;
317+
gotodone;
312318
}
313319
Py_DECREF(v);
314320
}
321+
322+
done:
315323
endpwent();
324+
#ifdefPy_GIL_DISABLED
325+
PyMutex_Unlock(&getpwall_mutex);
326+
#endif
327+
if (failure) {
328+
Py_XDECREF(v);
329+
Py_CLEAR(d);
330+
}
316331
returnd;
317332
}
318333
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp