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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-02-20T06:58:22+01:00

core: tcp read - checks for MSRP first line

---

Modified: src/core/tcp_read.c

---

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

---

diff --git a/src/core/tcp_read.c b/src/core/tcp_read.c
index 2cf24246be7..fed840d1c60 100644
--- a/src/core/tcp_read.c
+++ b/src/core/tcp_read.c
@@ -1042,11 +1042,31 @@ int tcp_read_headers(struct tcp_connection *c, 
rd_conn_flags_t *read_flags)
                                        /* locate transaction id in first line
                                         * -- first line exists, that's why we 
are here */
                                        mfline = q_memchr(r->start, '\n', 
r->pos - r->start);
-                                       mtransid.s = q_memchr(
-                                                       r->start + 5 /* 'MSRP ' 
*/, ' ', mfline - r->start);
+                                       if(mfline == NULL || mfline - r->start 
< 8) {
+                                               r->error = TCP_READ_ERROR;
+                                               r->state = H_SKIP; /* skip now 
*/
+                                               goto skip;
+                                       }
+                                       mtransid.s = q_memchr(r->start + 5 /* 
'MSRP ' */, ' ',
+                                                       mfline - r->start - 5);
+                                       if(mtransid.s == NULL) {
+                                               r->error = TCP_READ_ERROR;
+                                               r->state = H_SKIP; /* skip now 
*/
+                                               goto skip;
+                                       }
                                        mtransid.len = mtransid.s - r->start - 
5;
+                                       if(mtransid.len <= 0) {
+                                               r->error = TCP_READ_ERROR;
+                                               r->state = H_SKIP; /* skip now 
*/
+                                               goto skip;
+                                       }
                                        mtransid.s = r->start + 5;
                                        trim(&mtransid);
+                                       if(mtransid.len <= 0) {
+                                               r->error = TCP_READ_ERROR;
+                                               r->state = H_SKIP; /* skip now 
*/
+                                               goto skip;
+                                       }
                                        if(memcmp(mtransid.s,
                                                           p - 1 /*\r*/ - 1 /* 
'+'|'#'|'$' */
                                                                           - 
mtransid.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