From: Christian Göttsche <cgzones@xxxxxxxxxxxxxx> Character checking functions, like isspace(3), take an unsigned char as input, and passing any other value is undefined behavior. Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx> --- libsemanage/src/conf-scan.l | 4 ++-- libsemanage/src/genhomedircon.c | 4 ++-- libsemanage/src/modules.c | 8 ++++---- libsemanage/src/parse_utils.c | 10 +++++----- libsemanage/src/semanage_store.c | 16 ++++++++-------- libsemanage/src/users_base_file.c | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libsemanage/src/conf-scan.l b/libsemanage/src/conf-scan.l index b06a896c..bc0630b9 100644 --- a/libsemanage/src/conf-scan.l +++ b/libsemanage/src/conf-scan.l @@ -78,11 +78,11 @@ args return PROG_ARGS; * Returns NULL on error. */ static char *my_strdup(char *s) { char *t; - while (isspace(*s)) { + while (isspace((unsigned char)*s)) { s++; } t = s + strlen(s) - 1; - while (t >= s && isspace(*t)) { + while (t >= s && isspace((unsigned char)*t)) { *t = '\0'; t--; } diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c index 34b5ff93..31c9a5bf 100644 --- a/libsemanage/src/genhomedircon.c +++ b/libsemanage/src/genhomedircon.c @@ -543,14 +543,14 @@ static const char *extract_context(const char *line) while (off > 0) { p--; off--; - if (!isspace(*p)) + if (!isspace((unsigned char)*p)) break; } if (off == 0) return NULL; /* find the last field in line */ - while (off > 0 && !isspace(*(p - 1))) { + while (off > 0 && !isspace((unsigned char)*(p - 1))) { p--; off--; } diff --git a/libsemanage/src/modules.c b/libsemanage/src/modules.c index eeb85be6..e6a47362 100644 --- a/libsemanage/src/modules.c +++ b/libsemanage/src/modules.c @@ -819,12 +819,12 @@ int semanage_module_validate_name(const char * name) goto exit; } - if (!isalpha(*name)) { + if (!isalpha((unsigned char)*name)) { status = -1; goto exit; } -#define ISVALIDCHAR(c) (isalnum(c) || c == '_' || c == '-') +#define ISVALIDCHAR(c) (isalnum((unsigned char)c) || c == '_' || c == '-') for (name++; *name; name++) { if (ISVALIDCHAR(*name)) { @@ -876,12 +876,12 @@ int semanage_module_validate_lang_ext(const char *ext) goto exit; } - if (!isalnum(*ext)) { + if (!isalnum((unsigned char)*ext)) { status = -1; goto exit; } -#define ISVALIDCHAR(c) (isalnum(c) || c == '_' || c == '-') +#define ISVALIDCHAR(c) (isalnum((unsigned char)c) || c == '_' || c == '-') for (ext++; *ext; ext++) { if (ISVALIDCHAR(*ext)) { diff --git a/libsemanage/src/parse_utils.c b/libsemanage/src/parse_utils.c index 13837c87..d9b12763 100644 --- a/libsemanage/src/parse_utils.c +++ b/libsemanage/src/parse_utils.c @@ -90,7 +90,7 @@ int parse_skip_space(semanage_handle_t * handle, parse_info_t * info) char *ptr; if (info->ptr) { - while (*(info->ptr) && isspace(*(info->ptr))) + while (*(info->ptr) && isspace((unsigned char)*(info->ptr))) info->ptr++; if (*(info->ptr)) @@ -109,7 +109,7 @@ int parse_skip_space(semanage_handle_t * handle, parse_info_t * info) buffer[len - 1] = '\0'; ptr = buffer; - while (*ptr && isspace(*ptr)) + while (*ptr && isspace((unsigned char)*ptr)) ptr++; /* Skip comments and blank lines */ @@ -156,7 +156,7 @@ int parse_assert_space(semanage_handle_t * handle, parse_info_t * info) if (parse_assert_noeof(handle, info) < 0) return STATUS_ERR; - if (*(info->ptr) && !isspace(*(info->ptr))) { + if (*(info->ptr) && !isspace((unsigned char)*(info->ptr))) { ERR(handle, "missing whitespace (%s: %u):\n%s", info->filename, info->lineno, info->orig_line); return STATUS_ERR; @@ -242,7 +242,7 @@ int parse_fetch_int(semanage_handle_t * handle, if (parse_fetch_string(handle, info, &str, delim, 0) < 0) goto err; - if (!isdigit((int)*str)) { + if (!isdigit((unsigned char)*str)) { ERR(handle, "expected a numeric value: (%s: %u)\n%s", info->filename, info->lineno, info->orig_line); goto err; @@ -277,7 +277,7 @@ int parse_fetch_string(semanage_handle_t * handle, if (parse_assert_noeof(handle, info) < 0) goto err; - while (*(info->ptr) && (allow_spaces || !isspace(*(info->ptr))) && + while (*(info->ptr) && (allow_spaces || !isspace((unsigned char)*(info->ptr))) && (*(info->ptr) != delim)) { info->ptr++; len++; diff --git a/libsemanage/src/semanage_store.c b/libsemanage/src/semanage_store.c index 0684b2e8..f5c19e00 100644 --- a/libsemanage/src/semanage_store.c +++ b/libsemanage/src/semanage_store.c @@ -1409,7 +1409,7 @@ static char **split_args(const char *arg0, char *arg_string, break; } default:{ - if (isspace(*s) && !in_quote && !in_dquote) { + if (isspace((unsigned char)*s) && !in_quote && !in_dquote) { if (arg != NULL) { rc = append_arg(&argv, &num_args, arg); if (rc) @@ -2598,7 +2598,7 @@ int semanage_fc_sort(semanage_handle_t * sh, const char *buf, size_t buf_len, /* Skip the whitespace at the front of the line. */ for (i = 0; i < line_len; i++) { - if (!isspace(line_buf[i])) + if (!isspace((unsigned char)line_buf[i])) break; } @@ -2630,7 +2630,7 @@ int semanage_fc_sort(semanage_handle_t * sh, const char *buf, size_t buf_len, escape_chars = 0; just_saw_escape = 0; start = i; - while (i < line_len && (!isspace(line_buf[i]))) { + while (i < line_len && (!isspace((unsigned char)line_buf[i]))) { if (line_buf[i] == '\\') { if (!just_saw_escape) { escape_chars++; @@ -2666,7 +2666,7 @@ int semanage_fc_sort(semanage_handle_t * sh, const char *buf, size_t buf_len, /* Skip the whitespace after the regular expression. */ for (; i < line_len; i++) { - if (!isspace(line_buf[i])) + if (!isspace((unsigned char)line_buf[i])) break; } if (i == line_len) { @@ -2703,7 +2703,7 @@ int semanage_fc_sort(semanage_handle_t * sh, const char *buf, size_t buf_len, /* Skip the whitespace after the type. */ for (; i < line_len; i++) { - if (!isspace(line_buf[i])) + if (!isspace((unsigned char)line_buf[i])) break; } if (i == line_len) { @@ -2719,7 +2719,7 @@ int semanage_fc_sort(semanage_handle_t * sh, const char *buf, size_t buf_len, /* Extract the context from the line. */ start = i; - while (i < line_len && (!isspace(line_buf[i]))) + while (i < line_len && (!isspace((unsigned char)line_buf[i]))) i++; finish = i; context_len = finish - start; @@ -2914,7 +2914,7 @@ int semanage_nc_sort(semanage_handle_t * sh, const char *buf, size_t buf_len, /* Skip the whitespace at the front of the line. */ for (i = 0; i < line_len; i++) { - if (!isspace(line_buf[i])) + if (!isspace((unsigned char)line_buf[i])) break; } @@ -2950,7 +2950,7 @@ int semanage_nc_sort(semanage_handle_t * sh, const char *buf, size_t buf_len, } /* skip over whitespace */ - for (; offset < line_len && isspace(line_buf[offset]); + for (; offset < line_len && isspace((unsigned char)line_buf[offset]); offset++) ; /* load rule into node */ diff --git a/libsemanage/src/users_base_file.c b/libsemanage/src/users_base_file.c index 8fb00698..f4d15451 100644 --- a/libsemanage/src/users_base_file.c +++ b/libsemanage/src/users_base_file.c @@ -113,7 +113,7 @@ static int user_base_parse(semanage_handle_t * handle, start = info->ptr; while (*(info->ptr) && *(info->ptr) != ';' && - *(info->ptr) != '}' && !isspace(*(info->ptr))) + *(info->ptr) != '}' && !isspace((unsigned char)*(info->ptr))) info->ptr++; delim = *(info->ptr); @@ -122,7 +122,7 @@ static int user_base_parse(semanage_handle_t * handle, if (semanage_user_base_add_role(handle, user, start) < 0) goto err; - if (delim && !isspace(delim)) { + if (delim && !isspace((unsigned char)delim)) { if (islist && delim == '}') break; else if (!islist && delim == ';') -- 2.45.2