]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: tree-wide: cast arguments to tolower/toupper to unsigned char
authorWilly Tarreau <w@1wt.eu>
Sun, 5 Jul 2020 19:46:32 +0000 (21:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 5 Jul 2020 19:50:02 +0000 (21:50 +0200)
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
src/h1.c
src/pattern.c
src/regex.c
src/ssl_sock.c
src/tools.c

index 6f951ab5a8a729001af2fcc3b6f717e239c81e77..49b1c49d952ca3478cd6ebf0f7bcea62076f2822 100644 (file)
--- 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;
 }
index 368eb142cece7089deb13dd5526f7f48b26b988e..bb8acfb345d970d85be19b6f68d89d11c5832691 100644 (file)
--- 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);
                }
index 416e809638552d2ea80eeee08de9a1f5d9433172..a404ac34dd94f8043b583a8d84b137d1a4f68bdb 100644 (file)
@@ -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;
index e23e311521cc38ec47b51f455157bb67114be226..503be0378ab6e46b3d74b741a8ca11313d418723 100644 (file)
@@ -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;
index a32db1a28a3824418342f2e7d3284191bfd23eb6..02967f65d42035038adc6372464d6972a33261cb 100644 (file)
@@ -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);
index 39a4538bcd68afdcbec248900700d525bdf7eca1..f4f96a6d0707970c800e24b670136e32cb0df06f 100644 (file)
@@ -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;