[Asterisk-code-review] chan_sip.c: Stop handling continuation lines after reading headers (asterisk[master])

Friendly Automation asteriskteam at digium.com
Tue Jan 21 08:25:20 CST 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/13640 )

Change subject: chan_sip.c: Stop handling continuation lines after reading headers
......................................................................

chan_sip.c: Stop handling continuation lines after reading headers

lws2sws() does not stop trying to handle header continuation lines
even after all headers have been found. This is problematic if the
first character of a SIP message body is a space or tab character, so
we update to recognize the end of the message header.

ASTERISK-28693 #close
Reported by: Frank Matano

Change-Id: Idec8fa58545cd3fd898cbe0075d76c223f8d33df
---
M channels/chan_sip.c
1 file changed, 14 insertions(+), 3 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 7448951..e3b8afd 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -9869,8 +9869,10 @@
 	int len = ast_str_strlen(data);
 	int h = 0, t = 0;
 	int lws = 0;
+	int just_read_eol = 0;
+	int done_with_headers = 0;
 
-	for (; h < len;) {
+	while (h < len) {
 		/* Eliminate all CRs */
 		if (msgbuf[h] == '\r') {
 			h++;
@@ -9878,11 +9880,17 @@
 		}
 		/* Check for end-of-line */
 		if (msgbuf[h] == '\n') {
+			if (just_read_eol) {
+				done_with_headers = 1;
+			} else {
+				just_read_eol = 1;
+			}
 			/* Check for end-of-message */
 			if (h + 1 == len)
 				break;
 			/* Check for a continuation line */
-			if (msgbuf[h + 1] == ' ' || msgbuf[h + 1] == '\t') {
+			if (!done_with_headers
+			   && (msgbuf[h + 1] == ' ' || msgbuf[h + 1] == '\t')) {
 				/* Merge continuation line */
 				h++;
 				continue;
@@ -9891,8 +9899,11 @@
 			msgbuf[t++] = msgbuf[h++];
 			lws = 0;
 			continue;
+		} else {
+			just_read_eol = 0;
 		}
-		if (msgbuf[h] == ' ' || msgbuf[h] == '\t') {
+		if (!done_with_headers
+		   && (msgbuf[h] == ' ' || msgbuf[h] == '\t')) {
 			if (lws) {
 				h++;
 				continue;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13640
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Idec8fa58545cd3fd898cbe0075d76c223f8d33df
Gerrit-Change-Number: 13640
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200121/b00021aa/attachment.html>


More information about the asterisk-code-review mailing list