src/sss_client/common.c: Use getpwnam_r to avoid clobbering struct passwd#8487
src/sss_client/common.c: Use getpwnam_r to avoid clobbering struct passwd#8487salahcoronya wants to merge 1 commit intoSSSD:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request correctly replaces the non-thread-safe getpwnam with its re-entrant version, getpwnam_r, to prevent potential data corruption when multiple threads are involved. The implementation follows the standard pattern for using getpwnam_r, including dynamic buffer allocation and resizing. However, I've found a potential memory leak in the error handling of realloc and provided a suggestion to fix it.
b66af65 to
c37669a
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly replaces the non-reentrant getpwnam with the reentrant getpwnam_r to prevent thread-safety issues. The implementation for handling ERANGE is mostly correct, but it has a potential denial-of-service vulnerability due to unbounded memory allocation. I've added a review comment with a suggested fix to address this by adding a size limit to the buffer.
|
Hi @salahcoronya, I think this reports a valid bug, thanks. But there is a number of (at least) stylistic issues (re SSSD coding style) with the patch. |
c37669a to
8084fb6
Compare
|
I went ahead and finalized it myself, follow the coding style document. |
8084fb6 to
894f67c
Compare
…sswd If something else uses PAM (like openrc, see OpenRC/openrc#984) and getpwnam, and calls something like pam_open_session, sssd's call to getpwnam in init_sssd_ids clobbers the cached value by the other program. Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
894f67c to
6c85770
Compare
If something else uses PAM (like openrc, see
OpenRC/openrc#984) and getpwnam, and calls something like pam_open_session, sssd's call to getpwnam in init_sssd_ids clobbers the cached value by the other program.