Module: kamailio
Branch: master
Commit: 46accd70c68ab410d3f87d4188aee8dbc7c60673
URL: 
https://github.com/kamailio/kamailio/commit/46accd70c68ab410d3f87d4188aee8dbc7c60673

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-05-14T13:20:12+02:00

imc: check for content-type for building response headers

---

Modified: src/modules/imc/imc_cmd.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/46accd70c68ab410d3f87d4188aee8dbc7c60673.diff
Patch: 
https://github.com/kamailio/kamailio/commit/46accd70c68ab410d3f87d4188aee8dbc7c60673.patch

---

diff --git a/src/modules/imc/imc_cmd.c b/src/modules/imc/imc_cmd.c
index 009b35d4c0d..38d19fdd2c2 100644
--- a/src/modules/imc/imc_cmd.c
+++ b/src/modules/imc/imc_cmd.c
@@ -110,9 +110,14 @@ static str *build_headers(struct sip_msg *msg)
        static char buf[1024];
        static str rv = {NULL, 0};
        str *callid;
+       str ctbody = STR_NULL;
 
        rv.s = buf;
-       rv.len = all_hdrs.len + ctname.len + msg->content_type->body.len;
+       rv.len = all_hdrs.len;
+       if(msg->content_type != NULL) {
+               ctbody = msg->content_type->body;
+               rv.len += ctname.len + ctbody.len;
+       }
 
        if(rv.len > sizeof(buf)) {
                LM_ERR("headers too long\n");
@@ -120,9 +125,10 @@ static str *build_headers(struct sip_msg *msg)
        }
 
        memcpy(buf, all_hdrs.s, all_hdrs.len);
-       memcpy(buf + all_hdrs.len, ctname.s, ctname.len);
-       memcpy(buf + all_hdrs.len + ctname.len, msg->content_type->body.s,
-                       msg->content_type->body.len);
+       if(ctbody.len > 0) {
+               memcpy(buf + all_hdrs.len, ctname.s, ctname.len);
+               memcpy(buf + all_hdrs.len + ctname.len, ctbody.s, ctbody.len);
+       }
 
        if((callid = get_callid(msg)) == NULL) {
                return &rv;
@@ -135,13 +141,10 @@ static str *build_headers(struct sip_msg *msg)
                return &rv;
        }
 
-       memcpy(buf + all_hdrs.len + ctname.len + msg->content_type->body.len, 
nl.s,
-                       nl.len);
-       memcpy(buf + all_hdrs.len + ctname.len + msg->content_type->body.len
-                                       + nl.len,
-                       name.s, name.len);
-       memcpy(buf + all_hdrs.len + ctname.len + msg->content_type->body.len
-                                       + nl.len + name.len,
+       memcpy(buf + all_hdrs.len + ctname.len + ctbody.len, nl.s, nl.len);
+       memcpy(buf + all_hdrs.len + ctname.len + ctbody.len + nl.len, name.s,
+                       name.len);
+       memcpy(buf + all_hdrs.len + ctname.len + ctbody.len + nl.len + name.len,
                        callid->s, callid->len);
        return &rv;
 }

_______________________________________________
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