[sr-dev] git:3.3: modules_k/nathelper: fix a= lines inserted out of order

Richard Fuchs rfuchs at sipwise.com
Wed Aug 29 21:56:28 CEST 2012


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

Author: Richard Fuchs <rfuchs at sipwise.com>
Committer: Richard Fuchs <rfuchs at sipwise.com>
Date:   Wed Aug 29 15:47:10 2012 -0400

modules_k/nathelper: fix a= lines inserted out of order

RFC 4566 dictates a particular order of fields in the SDP body, in particular
media-specific a= lines must be last fields within an m= block. Inserting
them right after the m= lines violates this order if other fields (such as
c=) are present, causing parse errors in some clients. So instead, insert
them at the end of each m= block.

---

 modules_k/nathelper/nathelper.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c
index bec490c..a7f20a4 100644
--- a/modules_k/nathelper/nathelper.c
+++ b/modules_k/nathelper/nathelper.c
@@ -1370,7 +1370,7 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
 	str body;
 	str ip;
 	int level, rest_len;
-	char *buf, *m_start, *m_end, *rest_s;
+	char *buf, *m_start, *m_end;
 	struct lump* anchor;
 
 	level = (int)(long)str1;
@@ -1389,13 +1389,11 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
 		if (level & ADD_ADIRECTION) {
 		    m_start = ser_memmem(body.s, "\r\nm=", body.len, 4);
 		    while (m_start != NULL) {
-			m_start = m_start + 2;
+			m_start += 4;
 			rest_len = body.len - (m_start - body.s);
-			m_end = ser_memmem(m_start, "\r\n", rest_len, 2);
-			if (m_end == NULL) {
-			    LM_ERR("m line is not crlf terminated\n");
-			    return -1;
-			}
+			m_start = m_end = ser_memmem(m_start, "\r\nm=", rest_len, 4);
+			if (!m_end)
+				m_end = body.s + body.len; /* just before the final \r\n */
 		        anchor = anchor_lump(msg, m_end - msg->buf, 0, 0);
 		        if (anchor == NULL) {
 			    LM_ERR("anchor_lump failed\n");
@@ -1413,9 +1411,6 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
 			    pkg_free(buf);
 			    return -1;
 			}
-			rest_s = m_end + 2;
-			rest_len = body.len - (rest_s - body.s);
-			m_start = ser_memmem(rest_s, "\r\nm=", rest_len, 4);
 		    }
 		}
 




More information about the sr-dev mailing list