Module: kamailio Branch: master Commit: f52a278b35ee369e9e4e489aa191f437f81aaf0d URL: https://github.com/kamailio/kamailio/commit/f52a278b35ee369e9e4e489aa191f437f81aaf0d
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2026-05-10T11:24:01+02:00 core: check input and use for-loop for urlencode() --- Modified: src/core/strutils.c --- Diff: https://github.com/kamailio/kamailio/commit/f52a278b35ee369e9e4e489aa191f437f81aaf0d.diff Patch: https://github.com/kamailio/kamailio/commit/f52a278b35ee369e9e4e489aa191f437f81aaf0d.patch --- diff --git a/src/core/strutils.c b/src/core/strutils.c index eaa75035c0b..ad5c814663b 100644 --- a/src/core/strutils.c +++ b/src/core/strutils.c @@ -907,26 +907,26 @@ int urlencode(str *sin, str *sout) */ int urldecode(str *sin, str *sout) { - char *at, *p; - char *end; + char *at; + int i; + + if(sin == NULL || sout == NULL || sin->s == NULL || sout->s == NULL + || sin->len < 0 || sout->len < sin->len + 1) + return -1; at = sout->s; - p = sin->s; - end = sin->s + sin->len; - - while(p < end) { - if(*p == '%') { - if(p + 2 < end) { - *at++ = (((unsigned char)hex_to_char(p[1])) << 4) - | (unsigned char)hex_to_char(p[2]); - p += 2; + for(i = 0; i < sin->len; i++) { + if(sin->s[i] == '%') { + if(i + 2 < sin->len) { + *at++ = (((unsigned char)hex_to_char(sin->s[i + 1])) << 4) + | (unsigned char)hex_to_char(sin->s[i + 2]); + i += 2; } - } else if(*p == '+') { + } else if(sin->s[i] == '+') { *at++ = ' '; } else { - *at++ = *p; + *at++ = sin->s[i]; } - p++; } *at = 0; _______________________________________________ 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!
