From f278eec37aa2d4de028ade89951af9f894ee4d87 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 5 Jul 2020 21:46:32 +0200 Subject: [PATCH] BUILD: tree-wide: cast arguments to tolower/toupper to unsigned char NetBSD apparently uses macros for tolower/toupper and complains about the use of char for array subscripts. Let's properly cast all of them to unsigned char where they are used. This is needed to fix issue #729. --- src/dns.c | 2 +- src/h1.c | 2 +- src/pattern.c | 4 ++-- src/regex.c | 4 ++-- src/ssl_sock.c | 6 +++--- src/tools.c | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/dns.c b/src/dns.c index 6f951ab5a8..49b1c49d95 100644 --- a/src/dns.c +++ b/src/dns.c @@ -79,7 +79,7 @@ static __inline int dns_hostname_cmp(const char *name1, const char *name2, int l int i; for (i = 0; i < len; i++) - if (tolower(name1[i]) != tolower(name2[i])) + if (tolower((unsigned char)name1[i]) != tolower((unsigned char)name2[i])) return -1; return 0; } diff --git a/src/h1.c b/src/h1.c index 368eb142ce..bb8acfb345 100644 --- a/src/h1.c +++ b/src/h1.c @@ -662,7 +662,7 @@ int h1_headers_to_hdr_list(char *start, const char *stop, if (!skip_update) { /* turn it to lower case if needed */ if (isupper((unsigned char)*ptr) && h1m->flags & H1_MF_TOLOWER) - *ptr = tolower(*ptr); + *ptr = tolower((unsigned char)*ptr); } EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_name, http_msg_ood, state, H1_MSG_HDR_NAME); } diff --git a/src/pattern.c b/src/pattern.c index 416e809638..a404ac34dd 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -782,7 +782,7 @@ struct pattern *pat_match_sub(struct sample *smp, struct pattern_expr *expr, int icase = expr->mflags & PAT_MF_IGNORE_CASE; if (icase) { for (c = smp->data.u.str.area; c <= end; c++) { - if (tolower(*c) != tolower(*pattern->ptr.str)) + if (tolower((unsigned char)*c) != tolower((unsigned char)*pattern->ptr.str)) continue; if (strncasecmp(pattern->ptr.str, c, pattern->len) == 0) { ret = pattern; @@ -847,7 +847,7 @@ static int match_word(struct sample *smp, struct pattern *pattern, int mflags, u continue; if (icase) { - if ((tolower(*c) == tolower(*ps)) && + if ((tolower((unsigned char)*c) == tolower((unsigned char)*ps)) && (strncasecmp(ps, c, pl) == 0) && (c == end || is_delimiter(c[pl], delimiters))) return PAT_MATCH; diff --git a/src/regex.c b/src/regex.c index e23e311521..503be0378a 100644 --- a/src/regex.c +++ b/src/regex.c @@ -57,12 +57,12 @@ int exp_replace(char *dst, unsigned int dst_size, char *src, const char *str, co if (!*str) return -1; - hex1 = toupper(*str++) - '0'; + hex1 = toupper((unsigned char)*str++) - '0'; if (!*str) return -1; - hex2 = toupper(*str++) - '0'; + hex2 = toupper((unsigned char)*str++) - '0'; if (hex1 > 9) hex1 -= 'A' - '9' - 1; if (hex2 > 9) hex2 -= 'A' - '9' - 1; diff --git a/src/ssl_sock.c b/src/ssl_sock.c index a32db1a28a..02967f65d4 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -2386,7 +2386,7 @@ static int ssl_sock_switchctx_cbk(SSL *ssl, int *al, void *priv) for (i = 0; i < trash.size; i++) { if (!servername[i]) break; - trash.area[i] = tolower(servername[i]); + trash.area[i] = tolower((unsigned char)servername[i]); if (!wildp && (trash.area[i] == '.')) wildp = &trash.area[i]; } @@ -2681,7 +2681,7 @@ static int ckch_inst_add_cert_sni(SSL_CTX *ctx, struct ckch_inst *ckch_inst, int j, len; len = strlen(name); for (j = 0; j < len && j < trash.size; j++) - trash.area[j] = tolower(name[j]); + trash.area[j] = tolower((unsigned char)name[j]); if (j >= trash.size) return -1; trash.area[j] = 0; @@ -2985,7 +2985,7 @@ static int ssl_sock_populate_sni_keytypes_hplr(const char *str, struct eb_root * for (i = 0; i < trash.size; i++) { if (!str[i]) break; - trash.area[i] = tolower(str[i]); + trash.area[i] = tolower((unsigned char)str[i]); } trash.area[i] = 0; node = ebst_lookup(sni_keytypes, trash.area); diff --git a/src/tools.c b/src/tools.c index 39a4538bcd..f4f96a6d07 100644 --- a/src/tools.c +++ b/src/tools.c @@ -3921,7 +3921,7 @@ const char *strnistr(const char *str1, int len_str1, const char *str2, int len_s return NULL; for (tmp1 = 0, start = (char *)str1, pptr = (char *)str2, slen = len_str1, plen = len_str2; slen >= plen; start++, slen--) { - while (toupper(*start) != toupper(*str2)) { + while (toupper((unsigned char)*start) != toupper((unsigned char)*str2)) { start++; slen--; tmp1++; @@ -3938,7 +3938,7 @@ const char *strnistr(const char *str1, int len_str1, const char *str2, int len_s pptr = (char *)str2; tmp2 = 0; - while (toupper(*sptr) == toupper(*pptr)) { + while (toupper((unsigned char)*sptr) == toupper((unsigned char)*pptr)) { sptr++; pptr++; tmp2++; @@ -4882,8 +4882,8 @@ uint32_t parse_line(char *in, char *out, size_t *outlen, char **args, int *nbarg *errptr = in; goto leave; } - hex1 = toupper(in[2]) - '0'; - hex2 = toupper(in[3]) - '0'; + hex1 = toupper((unsigned char)in[2]) - '0'; + hex2 = toupper((unsigned char)in[3]) - '0'; if (hex1 > 9) hex1 -= 'A' - '9' - 1; if (hex2 > 9) hex2 -= 'A' - '9' - 1; tosend = (hex1 << 4) + hex2; -- 2.39.5