[asterisk-commits] kpfleming: branch 1.6.0 r149495 - in /branches/1.6.0: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 15 06:29:26 CDT 2008


Author: kpfleming
Date: Wed Oct 15 06:29:25 2008
New Revision: 149495

URL: http://svn.digium.com/view/asterisk?view=rev&rev=149495
Log:
Merged revisions 149487 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r149487 | kpfleming | 2008-10-15 13:26:36 +0200 (Wed, 15 Oct 2008) | 9 lines
  
  Merged revisions 149452 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r149452 | kpfleming | 2008-10-15 12:30:40 +0200 (Wed, 15 Oct 2008) | 3 lines
    
    fix some problems when parsing SIP messages that have the maximum number of headers or body lines that we support
  ........
................

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/channels/chan_sip.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/channels/chan_sip.c?view=diff&rev=149495&r1=149494&r2=149495
==============================================================================
--- branches/1.6.0/channels/chan_sip.c (original)
+++ branches/1.6.0/channels/chan_sip.c Wed Oct 15 06:29:25 2008
@@ -6207,51 +6207,82 @@
 {
 	char *c = req->data, **dst = req->header;
 	int i = 0, lim = SIP_MAX_HEADERS - 1;
+	unsigned int skipping_headers = 0;
 
 	req->header[0] = c;
 	req->headers = -1;	/* mark that we are working on the header */
 	for (; *c; c++) {
-		if (*c == '\r')		/* remove \r */
+		if (*c == '\r') {		/* remove \r */
 			*c = '\0';
-		else if (*c == '\n') { /* end of this line */
+		} else if (*c == '\n') { 	/* end of this line */
 			*c = '\0';
-			if (sipdebug)
+			if (skipping_headers) {
+				/* check to see if this line is blank; if so, turn off
+				   the skipping flag, so the next line will be processed
+				   as a body line */
+				if (ast_strlen_zero(dst[i])) {
+					skipping_headers = 0;
+				}
+				dst[i] = c + 1; /* record start of next line */
+				continue;
+			}
+			if (sipdebug) {
 				ast_debug(4, "%7s %2d [%3d]: %s\n",
-					req->headers < 0 ? "Header" : "Body",
-					i, (int)strlen(dst[i]), dst[i]);
+					  req->headers < 0 ? "Header" : "Body",
+					  i, (int) strlen(dst[i]), dst[i]);
+			}
 			if (ast_strlen_zero(dst[i]) && req->headers < 0) {
 				req->headers = i;	/* record number of header lines */
 				dst = req->line;	/* start working on the body */
 				i = 0;
 				lim = SIP_MAX_LINES - 1;
 			} else {	/* move to next line, check for overflows */
-				if (i++ >= lim)
-					break;
+				if (i++ == lim) {
+					/* if we're processing headers, then skip any remaining
+					   headers and move on to processing the body, otherwise
+					   we're done */
+					if (req->headers != -1) {
+						break;
+					} else {
+						req->headers = i;
+						dst = req->line;
+						i = 0;
+						lim = SIP_MAX_LINES - 1;
+						skipping_headers = 1;
+					}
+				}
 			}
 			dst[i] = c + 1; /* record start of next line */
 		}
         }
-	/* Check for last header without CRLF. The RFC for SDP requires CRLF,
-	   but since some devices send without, we'll be generous in what we accept.
+
+	/* Check for last header or body line without CRLF. The RFC for SDP requires CRLF,
+	   but since some devices send without, we'll be generous in what we accept. However,
+	   if we've already reached the maximum number of lines for portion of the message
+	   we were parsing, we can't accept any more, so just ignore it.
 	*/
-	if (!ast_strlen_zero(dst[i])) {
-		if (sipdebug)
+	if ((i < lim) && !ast_strlen_zero(dst[i])) {
+		if (sipdebug) {
 			ast_debug(4, "%7s %2d [%3d]: %s\n",
-				req->headers < 0 ? "Header" : "Body",
-				i, (int)strlen(dst[i]), dst[i]);
+				  req->headers < 0 ? "Header" : "Body",
+				  i, (int) strlen(dst[i]), dst[i]);
+		}
 		i++;
 	}
+
 	/* update count of header or body lines */
-	if (req->headers >= 0)	/* we are in the body */
+	if (req->headers >= 0) {	/* we are in the body */
 		req->lines = i;
-	else {			/* no body */
+	} else {			/* no body */
 		req->headers = i;
 		req->lines = 0;
 		req->line[0] = "";
 	}
 
-	if (*c)
+	if (*c) {
 		ast_log(LOG_WARNING, "Too many lines, skipping <%s>\n", c);
+	}
+
 	/* Split up the first line parts */
 	return determine_firstline_parts(req);
 }




More information about the asterisk-commits mailing list