Module: kamailio Branch: master Commit: 8247b56401401f258995ade7edd8602937a96b19 URL: https://github.com/kamailio/kamailio/commit/8247b56401401f258995ade7edd8602937a96b19
Author: Victor Seva <[email protected]> Committer: Victor Seva <[email protected]> Date: 2026-01-22T11:41:25+01:00 core: avoid unpredictable parsing behavior on platorms where char is signed * cast unsigned char before calling isalnum(), isdigit(), tolower() fixes #4563 --- Modified: src/core/parser/parse_identityinfo.c Modified: src/core/parser/parse_uri.c Modified: src/core/strutils.c --- Diff: https://github.com/kamailio/kamailio/commit/8247b56401401f258995ade7edd8602937a96b19.diff Patch: https://github.com/kamailio/kamailio/commit/8247b56401401f258995ade7edd8602937a96b19.patch --- diff --git a/src/core/parser/parse_identityinfo.c b/src/core/parser/parse_identityinfo.c index c28d0e80920..110c32fa73a 100644 --- a/src/core/parser/parse_identityinfo.c +++ b/src/core/parser/parse_identityinfo.c @@ -299,7 +299,8 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b) status = II_URI_IPV4; case II_URI_IPV4: case II_URI_IPV6: - if(isalnum(*p) || *p == '-' || *p == '.' || *p == ':') + if(isalnum((unsigned char)(*p)) || *p == '-' + || *p == '.' || *p == ':') break; case II_START: goto parseerror; diff --git a/src/core/parser/parse_uri.c b/src/core/parser/parse_uri.c index fd28fba7b08..8b6c1316f6f 100644 --- a/src/core/parser/parse_uri.c +++ b/src/core/parser/parse_uri.c @@ -642,7 +642,7 @@ int parse_uri(char *buf, int len, struct sip_uri *uri) if(*p == '[') { state = URI_HOST6_P; } else { - if(isalnum(*p)) { + if(isalnum((unsigned char)(*p))) { state = URI_HOST_P; } else { goto error_bad_host; @@ -653,8 +653,8 @@ int parse_uri(char *buf, int len, struct sip_uri *uri) switch(*p) { check_host_end; default: - if(!isalnum(*p) && (*p != '.') && (*p != '-') - && !uri_host_char_allowed(*p)) { + if(!isalnum((unsigned char)(*p)) && (*p != '.') + && (*p != '-') && !uri_host_char_allowed(*p)) { goto error_bad_host; } } diff --git a/src/core/strutils.c b/src/core/strutils.c index 50b7b0730c7..e6d60f74ba3 100644 --- a/src/core/strutils.c +++ b/src/core/strutils.c @@ -846,7 +846,9 @@ int reg_replace(char *pattern, char *replacement, char *string, str *result) /* Converts a hex character to its integer value */ char hex_to_char(char hex_code) { - return isdigit(hex_code) ? hex_code - '0' : tolower(hex_code) - 'a' + 10; + return isdigit((unsigned char)hex_code) + ? hex_code - '0' + : tolower((unsigned char)hex_code) - 'a' + 10; } /* Converts an integer value to its hex character */ @@ -871,7 +873,8 @@ int urlencode(str *sin, str *sout) p = sin->s; while(p < sin->s + sin->len) { - if(isalnum(*p) || *p == '-' || *p == '_' || *p == '.' || *p == '~') + if(isalnum((unsigned char)(*p)) || *p == '-' || *p == '_' || *p == '.' + || *p == '~') *at++ = *p; else *at++ = '%', *at++ = char_to_hex((unsigned char)(*p) >> 4), _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
