[sr-dev] git:3.3: core: tcp - proper handling of '\n-' sequence for detecting end of MSRP frame

Daniel-Constantin Mierla miconda at gmail.com
Tue Dec 18 16:04:23 CET 2012


Module: sip-router
Branch: 3.3
Commit: 42f2244abefcb157249e2311914a6d0f47396b5e
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=42f2244abefcb157249e2311914a6d0f47396b5e

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Fri Nov  9 11:03:46 2012 +0100

core: tcp - proper handling of '\n-' sequence for detecting end of MSRP frame

- in some cases it could go in wrong reading MSRP state
- reported by Gavin Llewellyn
(cherry picked from commit b255c406ba09ff229361a3bc14cc1c9fd076b52e)

---

 tcp_read.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tcp_read.c b/tcp_read.c
index f73a239..99deef2 100644
--- a/tcp_read.c
+++ b/tcp_read.c
@@ -934,14 +934,16 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 					if(r->pos - r->start < 10) {
 						LM_ERR("weird situation when reading MSRP frame"
 								" - continue reading\n");
+						/* *p=='\n' */
+						r->state=H_MSRP_BODY_LF;
 						p++;
-						r->state=H_MSRP_BODY;
 						break;
 					}
 					if(*(p-1)!='\r') {
 						/* not ending in '\r\n' - not end-line */
+						/* *p=='\n' */
+						r->state=H_MSRP_BODY_LF;
 						p++;
-						r->state=H_MSRP_BODY;
 						break;
 					}
 					/* locate transaction id in first line
@@ -956,16 +958,18 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 							p - 1 /*\r*/ - 1 /* '+'|'#'|'$' */ - mtransid.len,
 							mtransid.len)!=0) {
 						/* no match on session id - not end-line */
+						/* *p=='\n' */
+						r->state=H_MSRP_BODY_LF;
 						p++;
-						r->state=H_MSRP_BODY;
 						break;
 					}
 					if(memcmp(p - 1 /*\r*/ - 1 /* '+'|'#'|'$' */ - mtransid.len
 								- 7 /* 7 x '-' */ - 1 /* '\n' */, "\n-------",
 								8)!=0) {
 						/* no match on "\n-------" - not end-line */
+						/* *p=='\n' */
+						r->state=H_MSRP_BODY_LF;
 						p++;
-						r->state=H_MSRP_BODY;
 						break;
 					}
 					r->state=H_MSRP_FINISH;




More information about the sr-dev mailing list