Module: kamailio
Branch: master
Commit: 15da24b6c0d9ffc04d5ffaba15c95ce9741b16d3
URL: 
https://github.com/kamailio/kamailio/commit/15da24b6c0d9ffc04d5ffaba15c95ce9741b16d3

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-05-02T19:34:16+02:00

core: strutils - proper size for control chars in ksr_str_json_escape()

---

Modified: src/core/strutils.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/15da24b6c0d9ffc04d5ffaba15c95ce9741b16d3.diff
Patch: 
https://github.com/kamailio/kamailio/commit/15da24b6c0d9ffc04d5ffaba15c95ce9741b16d3.patch

---

diff --git a/src/core/strutils.c b/src/core/strutils.c
index f3c890cf4a2..154dc08a866 100644
--- a/src/core/strutils.c
+++ b/src/core/strutils.c
@@ -945,12 +945,22 @@ void ksr_str_json_escape(str *s_in, str *s_out, int 
*emode)
                return;
        }
        for(i = 0; i < s_in->len; i++) {
-               if(strchr("\"\\\b\f\n\r\t", s_in->s[i])) {
-                       len += 2;
-               } else if(s_in->s[i] < 32) {
-                       len += 6;
-               } else {
-                       len++;
+               switch(s_in->s[i]) {
+                       case '\"':
+                       case '\\':
+                       case '\b':
+                       case '\f':
+                       case '\n':
+                       case '\r':
+                       case '\t':
+                               len += 2;
+                               break;
+                       default:
+                               if((unsigned char)s_in->s[i] < 32) {
+                                       len += 6;
+                               } else {
+                                       len++;
+                               }
                }
        }
        if(len == s_in->len) {

_______________________________________________
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!

Reply via email to