From b8429cc8036cd23d075174d13eedc6d857e2b454 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Sun, 10 Dec 2023 14:20:32 +0000 Subject: pam_unix: check str to integer conversions Print an error in syslog if an integer could not be converted. Signed-off-by: Tobias Stoeckmann --- modules/pam_unix/passverify.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'modules/pam_unix/passverify.c') diff --git a/modules/pam_unix/passverify.c b/modules/pam_unix/passverify.c index 930c7d3c..98f997d5 100644 --- a/modules/pam_unix/passverify.c +++ b/modules/pam_unix/passverify.c @@ -5,6 +5,7 @@ #include #include #include "support.h" +#include #include #include #include @@ -703,7 +704,8 @@ save_old_password(pam_handle_t *pamh, const char *forwho, const char *oldpass, while (fgets(buf, 16380, opwfile)) { if (!strncmp(buf, forwho, len) && strchr(":,\n", buf[len]) != NULL) { - char *sptr = NULL; + char *ep, *sptr = NULL; + long value; found = 1; if (howmany == 0) continue; @@ -724,7 +726,11 @@ save_old_password(pam_handle_t *pamh, const char *forwho, const char *oldpass, continue; } s_pas = strtok_r(NULL, ":", &sptr); - npas = strtol(s_npas, NULL, 10) + 1; + value = strtol(s_npas, &ep, 10); + if (value < 0 || value >= INT_MAX || s_npas == ep || *ep != '\0') + npas = 0; + else + npas = (int)value + 1; while (npas > howmany && s_pas != NULL) { s_pas = strpbrk(s_pas, ","); if (s_pas != NULL) -- cgit v1.2.3