Skip to content

Commit 1ad4f80

Browse files
committed
dmq: check the result of printing headers
1 parent 8f912d2 commit 1ad4f80

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/modules/dmq/dmq_funcs.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,20 @@ int dmq_send_message(dmq_peer_t *peer, str *body, dmq_node_t *node,
236236
return -1;
237237
}
238238
/* add Max-Forwards and Content-Type headers */
239-
str_hdr.len = 34 + content_type->len + (CRLF_LEN * 2);
239+
str_hdr.len = 40 + content_type->len + (CRLF_LEN * 2);
240240
str_hdr.s = pkg_malloc(str_hdr.len);
241241
if(str_hdr.s == NULL) {
242242
PKG_MEM_ERROR;
243243
return -1;
244244
}
245-
len += sprintf(str_hdr.s, "Max-Forwards: %d" CRLF "Content-Type: %.*s" CRLF,
246-
max_forwards, content_type->len, content_type->s);
245+
len = snprintf(str_hdr.s, str_hdr.len,
246+
"Max-Forwards: %d" CRLF "Content-Type: %.*s" CRLF, max_forwards,
247+
content_type->len, content_type->s);
248+
if(len < 0 || len >= str_hdr.len) {
249+
LM_ERR("failed to create the headers\n");
250+
pkg_free(str_hdr.s);
251+
return -1;
252+
}
247253
str_hdr.len = len;
248254

249255
cb_param = shm_malloc(sizeof(*cb_param));

0 commit comments

Comments
 (0)