From 86506bddaa02e845c87f6513e04e109c4e3c78ff Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Tue, 12 Dec 2023 17:03:05 +0100 Subject: pam_xauth: simplify check_acl The strcspn function can easily replace memchr here. The latter would scan the entire buffer and requires a manual size limitation. Signed-off-by: Tobias Stoeckmann --- modules/pam_xauth/pam_xauth.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'modules/pam_xauth/pam_xauth.c') diff --git a/modules/pam_xauth/pam_xauth.c b/modules/pam_xauth/pam_xauth.c index 35bc5aeb..bc8a3d74 100644 --- a/modules/pam_xauth/pam_xauth.c +++ b/modules/pam_xauth/pam_xauth.c @@ -290,17 +290,10 @@ check_acl(pam_handle_t *pamh, } } if (fp) { - char buf[LINE_MAX], *tmp; + char buf[LINE_MAX]; /* Scan the file for a list of specs of users to "trust". */ while (fgets(buf, sizeof(buf), fp) != NULL) { - tmp = memchr(buf, '\r', sizeof(buf)); - if (tmp != NULL) { - *tmp = '\0'; - } - tmp = memchr(buf, '\n', sizeof(buf)); - if (tmp != NULL) { - *tmp = '\0'; - } + buf[strcspn(buf, "\r\n")] = '\0'; if (fnmatch(buf, other_user, 0) == 0) { if (debug) { pam_syslog(pamh, LOG_DEBUG, -- cgit v1.2.3