aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2023-08-07 12:46:27 +0200
committerDmitry V. Levin <ldv@strace.io>2023-08-07 10:46:40 +0000
commit65b5747e32067ffd1980ef06360737b3c30b0feb (patch)
tree1dab52c52d6149d35b57f2134bc70cf2d807b423
parent2770046cd8c24eae69625f7cbab0b6995008bbf7 (diff)
downloadpam-65b5747e32067ffd1980ef06360737b3c30b0feb.tar.gz
pam-65b5747e32067ffd1980ef06360737b3c30b0feb.tar.bz2
pam-65b5747e32067ffd1980ef06360737b3c30b0feb.zip
libpam: cast to unsigned char for character handling function
Character handling functions, like isspace(3), expect a value representable as unsigned char or equal to EOF. Otherwise the behavior is undefined. See https://wiki.sei.cmu.edu/confluence/display/c/STR37-C.+Arguments+to+character-handling+functions+must+be+representable+as+an+unsigned+char
-rw-r--r--libpam/pam_item.c2
-rw-r--r--libpam/pam_misc.c10
-rw-r--r--libpam/pam_modutil_searchkey.c4
-rw-r--r--libpam/pam_start.c2
4 files changed, 9 insertions, 9 deletions
diff --git a/libpam/pam_item.c b/libpam/pam_item.c
index 42857da5..90eafb2e 100644
--- a/libpam/pam_item.c
+++ b/libpam/pam_item.c
@@ -46,7 +46,7 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item)
{
char *tmp;
for (tmp=pamh->service_name; *tmp; ++tmp)
- *tmp = tolower(*tmp); /* require lower case */
+ *tmp = tolower((unsigned char)*tmp); /* require lower case */
}
break;
diff --git a/libpam/pam_misc.c b/libpam/pam_misc.c
index 996f23ce..449490c9 100644
--- a/libpam/pam_misc.c
+++ b/libpam/pam_misc.c
@@ -273,7 +273,7 @@ void _pam_parse_control(int *control_array, char *tok)
int act, len;
/* skip leading space */
- while (isspace((int)*tok) && *++tok);
+ while (isspace((unsigned char)*tok) && *++tok);
if (!*tok)
break;
@@ -290,14 +290,14 @@ void _pam_parse_control(int *control_array, char *tok)
}
/* observe '=' */
- while (isspace((int)*tok) && *++tok);
+ while (isspace((unsigned char)*tok) && *++tok);
if (!*tok || *tok++ != '=') {
error = "expecting '='";
goto parse_error;
}
/* skip leading space */
- while (isspace((int)*tok) && *++tok);
+ while (isspace((unsigned char)*tok) && *++tok);
if (!*tok) {
error = "expecting action";
goto parse_error;
@@ -322,7 +322,7 @@ void _pam_parse_control(int *control_array, char *tok)
* cause looping problems. So, for now, we will just
* allow forward jumps. (AGM 1998/1/7)
*/
- if (!isdigit((int)*tok)) {
+ if (!isdigit((unsigned char)*tok)) {
error = "expecting jump number";
goto parse_error;
}
@@ -331,7 +331,7 @@ void _pam_parse_control(int *control_array, char *tok)
do {
act *= 10;
act += *tok - '0'; /* XXX - this assumes ascii behavior */
- } while (*++tok && isdigit((int)*tok));
+ } while (*++tok && isdigit((unsigned char)*tok));
if (! act) {
/* we do not allow 0 jumps. There is a token ('ignore')
for that */
diff --git a/libpam/pam_modutil_searchkey.c b/libpam/pam_modutil_searchkey.c
index ba023e52..6e577728 100644
--- a/libpam/pam_modutil_searchkey.c
+++ b/libpam/pam_modutil_searchkey.c
@@ -103,14 +103,14 @@ pam_modutil_search_key(pam_handle_t *pamh UNUSED,
tmp = strchr(cp, '#'); /* remove comments */
if (tmp)
*tmp = '\0';
- while (isspace((int)*cp)) /* remove spaces and tabs */
+ while (isspace((unsigned char)*cp)) /* remove spaces and tabs */
++cp;
if (*cp == '\0') /* ignore empty lines */
continue;
tmp = strsep (&cp, " \t=");
if (cp != NULL)
- while (isspace((int)*cp) || *cp == '=')
+ while (isspace((unsigned char)*cp) || *cp == '=')
++cp;
else
cp = buf + n; /* empty string */
diff --git a/libpam/pam_start.c b/libpam/pam_start.c
index 1fc36b3e..5e9b0948 100644
--- a/libpam/pam_start.c
+++ b/libpam/pam_start.c
@@ -67,7 +67,7 @@ static int _pam_start_internal (
char *tmp;
for (tmp=(*pamh)->service_name; *tmp; ++tmp)
- *tmp = tolower(*tmp); /* require lower case */
+ *tmp = tolower((unsigned char)*tmp); /* require lower case */
}
if (user) {