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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-06-26T11:57:35+02:00

tsilo: check is contact field is set

---

Modified: src/modules/tsilo/tsilo.c

---

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

---

diff --git a/src/modules/tsilo/tsilo.c b/src/modules/tsilo/tsilo.c
index 44440ff9d6d..9030ba6ebcf 100644
--- a/src/modules/tsilo/tsilo.c
+++ b/src/modules/tsilo/tsilo.c
@@ -432,6 +432,7 @@ static int w_ts_append_by_contact2(
 
        str contact = STR_NULL;
        str tmp_contact = STR_NULL;
+       contact_body_t *cb = NULL;
        struct sip_uri curi;
 
        int rc;
@@ -473,28 +474,25 @@ static int w_ts_append_by_contact2(
                        LM_WARN("failed to parse Contact header.\n");
                        goto error;
                }
-               if(parse_uri(((struct contact_body *)_msg->contact->parsed)
-                                                        ->contacts->uri.s,
-                                  ((struct contact_body 
*)_msg->contact->parsed)
-                                                  ->contacts->uri.len,
-                                  &curi)
-                               != 0) {
+               cb = (contact_body_t *)_msg->contact->parsed;
+               if(cb == NULL || cb->contacts == NULL) {
+                       LM_WARN("missing contact item in Contact header.\n");
+                       goto error;
+               }
+               if(parse_uri(cb->contacts->uri.s, cb->contacts->uri.len, &curi) 
!= 0) {
                        if(ts_check_uri(&_msg->contact->body) < 0) { /* one 
more attempt */
                                LM_WARN("failed to parse Contact header.\n");
                                goto error;
                        }
                }
 
-               tmp_contact.len = ((struct contact_body *)_msg->contact->parsed)
-                                                                 
->contacts->uri.len;
+               tmp_contact.len = cb->contacts->uri.len;
                tmp_contact.s = (char *)pkg_malloc(tmp_contact.len + 1);
                if(tmp_contact.s == NULL) {
                        PKG_MEM_ERROR;
                        goto error;
                }
-               memcpy(tmp_contact.s,
-                               ((struct contact_body 
*)_msg->contact->parsed)->contacts->uri.s,
-                               tmp_contact.len);
+               memcpy(tmp_contact.s, cb->contacts->uri.s, tmp_contact.len);
                tmp_contact.s[tmp_contact.len] = '\0';
 
                if(pkg_str_dup(&contact, &tmp_contact) < 0) {
@@ -538,6 +536,7 @@ static int ki_ts_append_by_contact(sip_msg_t *_msg, str 
*_table, str *_ruri)
        str ruri = STR_NULL;
        str contact = STR_NULL;
        str tmp_contact = STR_NULL;
+       contact_body_t *cb = NULL;
        struct sip_uri curi;
        int rc;
 
@@ -555,26 +554,21 @@ static int ki_ts_append_by_contact(sip_msg_t *_msg, str 
*_table, str *_ruri)
        if(_msg->contact) {
                if(parse_contact(_msg->contact) < 0)
                        goto error;
-               if(parse_uri(((struct contact_body *)_msg->contact->parsed)
-                                                        ->contacts->uri.s,
-                                  ((struct contact_body 
*)_msg->contact->parsed)
-                                                  ->contacts->uri.len,
-                                  &curi)
-                               != 0) {
+               cb = (contact_body_t *)_msg->contact->parsed;
+               if(cb == NULL || cb->contacts == NULL)
+                       goto error;
+               if(parse_uri(cb->contacts->uri.s, cb->contacts->uri.len, &curi) 
!= 0) {
                        if(ts_check_uri(&_msg->contact->body) < 0) /* one more 
attempt */
                                goto error;
                }
 
-               tmp_contact.len = ((struct contact_body *)_msg->contact->parsed)
-                                                                 
->contacts->uri.len;
+               tmp_contact.len = cb->contacts->uri.len;
                tmp_contact.s = (char *)pkg_malloc(tmp_contact.len + 1);
                if(tmp_contact.s == NULL) {
                        PKG_MEM_ERROR;
                        goto error;
                }
-               memcpy(tmp_contact.s,
-                               ((struct contact_body 
*)_msg->contact->parsed)->contacts->uri.s,
-                               tmp_contact.len);
+               memcpy(tmp_contact.s, cb->contacts->uri.s, tmp_contact.len);
                tmp_contact.s[tmp_contact.len] = '\0';
 
                if(pkg_str_dup(&contact, &tmp_contact) < 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!

Reply via email to