From 0024ad62ab988f849e6eddfae8e2066bbcb1f867 Mon Sep 17 00:00:00 2001
From: "Dwayne M. Hubbard" <dwayne.hubbard@gmail.com>
Date: Fri, 6 Feb 2009 23:51:56 +0000
Subject: [PATCH] Merged revisions 174082 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r174082 | dhubbard | 2009-02-06 17:36:03 -0600 (Fri, 06 Feb 2009) | 5 lines

check ast_strlen_zero() before calling ast_strdupa() in sip_uri_headers_cmp()
and sip_uri_params_cmp()

The reporter didn't actually upload a properly-formed patch, instead a
modified chan_sip.c file was uploaded.  I created a patch to determine the
changes, then modified the suggested changes to create a proper fix.  The
summary above is a complete description of the changes.

(closes issue #13547)
Reported by: tecnoxarxa
Patches:
      chan_sip.c.gz uploaded by tecnoxarxa (license 258)
Tested by: tecnoxarxa

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@174084 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_sip.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 365bd5b63b..a6d9c2c0a7 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -18221,19 +18221,32 @@ static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, in
  */
 static int sip_uri_params_cmp(const char *input1, const char *input2) 
 {
-	char *params1 = ast_strdupa(input1);
-	char *params2 = ast_strdupa(input2);
+	char *params1 = NULL;
+	char *params2 = NULL;
 	char *pos1;
 	char *pos2;
+	int zerolength1 = 0;
+	int zerolength2 = 0;
 	int maddrmatch = 0;
 	int ttlmatch = 0;
 	int usermatch = 0;
 	int methodmatch = 0;
 
+	if (ast_strlen_zero(input1)) {
+		zerolength1 = 1;
+	} else {
+		params1 = ast_strdupa(input1);
+	}
+	if (ast_strlen_zero(input2)) {
+		zerolength2 = 1;
+	} else {
+		params2 = ast_strdupa(input2);
+	}
+
 	/*Quick optimization. If both params are zero-length, then
 	 * they match
 	 */
-	if (ast_strlen_zero(params1) && ast_strlen_zero(params2)) {
+	if (zerolength1 && zerolength2) {
 		return 0;
 	}
 
@@ -18348,13 +18361,25 @@ fail:
  */
 static int sip_uri_headers_cmp(const char *input1, const char *input2)
 {
-	char *headers1 = ast_strdupa(input1);
-	char *headers2 = ast_strdupa(input2);
-	int zerolength1 = ast_strlen_zero(headers1);
-	int zerolength2 = ast_strlen_zero(headers2);
+	char *headers1 = NULL;
+	char *headers2 = NULL;
+	int zerolength1 = 0;
+	int zerolength2 = 0;
 	int different = 0;
 	char *header1;
 
+	if (ast_strlen_zero(input1)) {
+		zerolength1 = 1;
+	} else {
+		headers1 = ast_strdupa(input1);
+	}
+	
+	if (ast_strlen_zero(input2)) {
+		zerolength2 = 1;
+	} else {
+		headers2 = ast_strdupa(input2);
+	}
+
 	if ((zerolength1 && !zerolength2) ||
 			(zerolength2 && !zerolength1))
 		return 1;
-- 
GitLab