From 1a2b73ac0befb25b4d297649a96636ca830a79f5 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Tue, 2 Jan 2024 21:33:41 +0100 Subject: pam_unix: calculate user length only if needed Signed-off-by: Tobias Stoeckmann --- modules/pam_unix/support.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/pam_unix') diff --git a/modules/pam_unix/support.c b/modules/pam_unix/support.c index 5dd3b946..df5044e9 100644 --- a/modules/pam_unix/support.c +++ b/modules/pam_unix/support.c @@ -350,15 +350,16 @@ int _unix_getpwnam(pam_handle_t *pamh, const char *name, char *buf = NULL; int matched = 0; char *slogin, *spasswd, *suid, *sgid, *sgecos, *shome, *sshell, *p; - size_t retlen, userlen; + size_t retlen; - userlen = strlen(name); if (!matched && files && strchr(name, ':') == NULL) { passwd = fopen("/etc/passwd", "r"); if (passwd != NULL) { - size_t n = 0; + size_t n = 0, userlen; ssize_t r; + userlen = strlen(name); + while ((r = getline(&buf, &n, passwd)) != -1) { if ((size_t)r > userlen && (buf[userlen] == ':') && (strncmp(name, buf, userlen) == 0)) { -- cgit v1.2.3