aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2024-01-04 17:46:47 +0100
committerChristian Göttsche <cgzones@googlemail.com>2024-01-04 17:46:47 +0100
commit921386390effa5484fd11c7d36c1dfa84fd608a6 (patch)
tree355880e093a5538429b3e8a68d114a7aa4acf69c
parent4f0cf2eb43c73080789579f060a327d3d90fb0dc (diff)
downloadpam-921386390effa5484fd11c7d36c1dfa84fd608a6.tar.gz
pam-921386390effa5484fd11c7d36c1dfa84fd608a6.tar.bz2
pam-921386390effa5484fd11c7d36c1dfa84fd608a6.zip
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.
-rw-r--r--modules/pam_timestamp/pam_timestamp.c4
1 files changed, 2 insertions, 2 deletions
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