Skip to content

Commit

Permalink
pythongh-48511: Make pwd and grp recognizing that NULL also can mean …
Browse files Browse the repository at this point in the history
…an error
  • Loading branch information
arhadthedev committed Jul 12, 2022
1 parent cfafd3a commit 46c34b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:func:`pwd.getpwuid` and :func:`pwd.getpwall` now differentiate between a
lack of record (:data:`None` is returned) and a database access error
(:exc:`OSException` is risen) to be consistent with :func:`pwd.getpwnam`.
Path by Oleg Iarygin.
9 changes: 8 additions & 1 deletion Modules/pwdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,13 @@ pwd_getpwnam_impl(PyObject *module, PyObject *name)
if (nomem == 1) {
PyErr_NoMemory();
}
else {
else if (errno == 0) {
PyErr_Format(PyExc_KeyError,
"getpwnam(): name not found: %R", name);
}
else {
PyErr_SetFromErrno(PyExc_OSError)
}
goto out;
}
retval = mkpwent(module, p);
Expand Down Expand Up @@ -306,6 +309,10 @@ pwd_getpwall_impl(PyObject *module)
Py_DECREF(v);
}
endpwent();
if (p == NULL) {
PyErr_SetFromErrno(PyExc_OSError)
return NULL
}
return d;
}
#endif
Expand Down

0 comments on commit 46c34b6

Please sign in to comment.