Browse code

tm: safety check for CRLF at end of custom headers for local requests

- if hdrs value is not ending in '\n', add '\r\n'

Daniel-Constantin Mierla authored on 04/01/2015 22:55:18
Showing 1 changed files
... ...
@@ -1553,7 +1553,13 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, int bra
1553 1553
 	*len += CONTENT_LENGTH_LEN + content_length.len + CRLF_LEN; /* Content-Length */
1554 1554
 	*len += ((server_signature && user_agent_hdr.len>0)
1555 1555
 							? (user_agent_hdr.len + CRLF_LEN) : 0);	                         /* Signature */
1556
-	*len += (headers ? headers->len : 0);                                                        /* Additional headers */
1556
+	if(headers && headers->len>2) {
1557
+		/* Additional headers */
1558
+		*len += headers->len;
1559
+		/* End of header if missing */
1560
+		if(headers->s[headers->len - 1] != '\n')
1561
+			*len += CRLF_LEN;
1562
+	}
1557 1563
 	*len += (body ? body->len : 0);                                                              /* Message body */
1558 1564
 	*len += CRLF_LEN;                                                                            /* End of Header */
1559 1565
 
... ...
@@ -1586,7 +1592,11 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, int bra
1586 1592
 		memapp(w, user_agent_hdr.s, user_agent_hdr.len);
1587 1593
 		memapp(w, CRLF, CRLF_LEN);
1588 1594
 	}
1589
-	if (headers) memapp(w, headers->s, headers->len);
1595
+	if(headers && headers->len>2) {
1596
+		memapp(w, headers->s, headers->len);
1597
+		if(headers->s[headers->len - 1] != '\n')
1598
+			memapp(w, CRLF, CRLF_LEN);
1599
+	}
1590 1600
 	memapp(w, CRLF, CRLF_LEN);
1591 1601
 	if (body) memapp(w, body->s, body->len);
1592 1602