From 921386390effa5484fd11c7d36c1dfa84fd608a6 Mon Sep 17 00:00:00 2001 From: Christian Göttsche Date: Thu, 4 Jan 2024 17:46:47 +0100 Subject: pam_timestamp: fix condition order Check the array index first before dereferencing the array. Also convert the index type to size_t to avoid casting. Reported by cppcheck. --- modules/pam_timestamp/pam_timestamp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/pam_timestamp') diff --git a/modules/pam_timestamp/pam_timestamp.c b/modules/pam_timestamp/pam_timestamp.c index bf35db15..08300164 100644 --- a/modules/pam_timestamp/pam_timestamp.c +++ b/modules/pam_timestamp/pam_timestamp.c @@ -99,13 +99,13 @@ check_dir_perms(pam_handle_t *pamh, const char *tdir) { char scratch[BUFLEN] = {}; struct stat st; - int i; + size_t i; /* Check that the directory is "safe". */ if ((tdir == NULL) || (strlen(tdir) == 0)) { return PAM_AUTH_ERR; } /* Iterate over the path, checking intermediate directories. */ - for (i = 0; (tdir[i] != '\0') && (i < (int)sizeof(scratch)); i++) { + for (i = 0; (i < sizeof(scratch)) && (tdir[i] != '\0'); i++) { scratch[i] = tdir[i]; if ((scratch[i] == '/') || (tdir[i + 1] == '\0')) { /* We now have the name of a directory in the path, so -- cgit v1.2.3