Module: kamailio
Branch: 5.8
Commit: c32332d649fcf98e6da34f12b1c5c36fe9fa9b46
URL: 
https://github.com/kamailio/kamailio/commit/c32332d649fcf98e6da34f12b1c5c36fe9fa9b46

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-01-05T09:32:35+01:00

dmq: check the result of printing headers

(cherry picked from commit 1ad4f802a4827bbfa0b132e6a21146bbb22a3f84)
(cherry picked from commit f3e400533b2f26a6efec50a6714ea3b7c09e9d3f)

---

Modified: src/modules/dmq/dmq_funcs.c

---

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

---

diff --git a/src/modules/dmq/dmq_funcs.c b/src/modules/dmq/dmq_funcs.c
index 017d45a6d8d..ddfdab19302 100644
--- a/src/modules/dmq/dmq_funcs.c
+++ b/src/modules/dmq/dmq_funcs.c
@@ -229,14 +229,20 @@ int dmq_send_message(dmq_peer_t *peer, str *body, 
dmq_node_t *node,
                return -1;
        }
        /* add Max-Forwards and Content-Type headers */
-       str_hdr.len = 34 + content_type->len + (CRLF_LEN * 2);
+       str_hdr.len = 40 + content_type->len + (CRLF_LEN * 2);
        str_hdr.s = pkg_malloc(str_hdr.len);
        if(str_hdr.s == NULL) {
                PKG_MEM_ERROR;
                return -1;
        }
-       len += sprintf(str_hdr.s, "Max-Forwards: %d" CRLF "Content-Type: %.*s" 
CRLF,
-                       max_forwards, content_type->len, content_type->s);
+       len = snprintf(str_hdr.s, str_hdr.len,
+                       "Max-Forwards: %d" CRLF "Content-Type: %.*s" CRLF, 
max_forwards,
+                       content_type->len, content_type->s);
+       if(len < 0 || len >= str_hdr.len) {
+               LM_ERR("failed to create the headers\n");
+               pkg_free(str_hdr.s);
+               return -1;
+       }
        str_hdr.len = len;
 
        cb_param = shm_malloc(sizeof(*cb_param));

_______________________________________________
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