Skip to content
Closed
Changes from 2 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
9 changes: 8 additions & 1 deletion Modules/grpmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "Python.h"
#include "posixmodule.h"
#include "pycore_list.h" // _PyList_AppendTakeRef()
#include "pycore_object.h" // _PyObject_IsUniquelyReferenced()

#include <errno.h> // ERANGE
#include <grp.h> // getgrgid_r()
Expand Down Expand Up @@ -290,13 +292,18 @@ grp_getgrall_impl(PyObject *module)
setgrent();

struct group *p;
// `d` is a local list; append items without a lock using
// _PyList_AppendTakeRef() within the loop.
assert(_PyObject_IsUniquelyReferenced(d));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d is not passed anywhere, isn't this obvious? we never added such assertions where it was obvious like this case

while ((p = getgrent()) != NULL) {
// gh-126316: Don't release the mutex around mkgrent() since
// setgrent()/endgrent() are not reentrant / thread-safe. A deadlock
// is unlikely since mkgrent() should not be able to call arbitrary
// Python code.
PyObject *v = mkgrent(module, p);
if (v == NULL || PyList_Append(d, v) != 0) {
if (v == NULL
|| _PyList_AppendTakeRef((PyListObject *)d, Py_NewRef(v)) != 0)
{
Py_XDECREF(v);
Py_CLEAR(d);
goto done;
Expand Down
Loading