Module: kamailio Branch: 5.8 Commit: 4a5e3fbc54c6b8f362a9c31027f1f712bc616578 URL: https://github.com/kamailio/kamailio/commit/4a5e3fbc54c6b8f362a9c31027f1f712bc616578
Author: Victor Seva <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2026-03-05T18:01:03+01:00 core: avoid unpredictable parsing behavior on platorms where char is signed * cast unsigned char before calling isalnum(), isdigit(), tolower() fixes #4563 (cherry picked from commit 8247b56401401f258995ade7edd8602937a96b19) (cherry picked from commit 133b7c1dfdc853307513370daaeaadd715a83dc9) --- 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/4a5e3fbc54c6b8f362a9c31027f1f712bc616578.diff Patch: https://github.com/kamailio/kamailio/commit/4a5e3fbc54c6b8f362a9c31027f1f712bc616578.patch --- diff --git a/src/core/parser/parse_identityinfo.c b/src/core/parser/parse_identityinfo.c index fd5c80c6ed7..6402e4a3c51 100644 --- a/src/core/parser/parse_identityinfo.c +++ b/src/core/parser/parse_identityinfo.c @@ -297,7 +297,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 1063186f6c8..34e5874720d 100644 --- a/src/core/parser/parse_uri.c +++ b/src/core/parser/parse_uri.c @@ -630,7 +630,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; @@ -641,8 +641,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 73e713cb451..4967f6304ce 100644 --- a/src/core/strutils.c +++ b/src/core/strutils.c @@ -782,7 +782,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 */ @@ -807,7 +809,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!
