[svn-commits] trunk r31843 - /trunk/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sat Jun 3 15:56:46 MST 2006


Author: rizzo
Date: Sat Jun  3 17:56:45 2006
New Revision: 31843

URL: http://svn.digium.com/view/asterisk?rev=31843&view=rev
Log:
mark XXX a buggy section of code and implement a probable
replacement (leave the original in case my code does not
do what the function was meant to do).
oej, please check this...


Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=31843&r1=31842&r2=31843&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sat Jun  3 17:56:45 2006
@@ -11626,9 +11626,28 @@
 		*/
 		
 		/* Skip leading whitespace */
-		while(replace_id[0] && (replace_id[0] < 33))
-			memmove(replace_id, replace_id+1, strlen(replace_id));
-
+		replace_id = ast_skip_blanks(replace_id);
+
+		/* XXX there are several bugs in the code below,
+		 * because 'ptr' can be NULL so all the dereferences in strcasestr()
+		 * would cause panics.
+		 * I think we should do something like the code below, which also has
+		 * the advantage of not depending on the order of headers.
+		 * Please test if it works, and in case remove the block in #else / #endif
+		 */
+#if 1	/* proposed replacement */
+
+		start = replace_id;
+		while ( (ptr = strsep(&start, ";")) ) {
+			ptr = ast_skip_blanks(ptr); /* XXX maybe unnecessary ? */
+			if ( (to = strcasestr(ptr, "to-tag=") ) )
+				totag = to + 7;	/* skip the keyword */
+			else if ( (to = strcasestr(ptr, "from-tag=") ) ) {
+				fromtag = to + 9;	/* skip the keyword */
+				fromtag = strsep(&fromtag, "&"); /* trim what ? */
+			}
+		}
+#else	/* original code, buggy */
 		if ((ptr = strchr(replace_id, ';'))) {
 			*ptr = '\0';
 			ptr++;
@@ -11641,6 +11660,7 @@
 			totag = ptr;
 			if ((to = strchr(ptr, ';')))
 				*to = '\0';
+			/* XXX this code is also wrong as to can be NULL */
 			to++;
 			ptr = to;
 		}
@@ -11654,6 +11674,7 @@
 			if ((to = strchr(ptr, ';')))
 				*to = '\0';
 		}
+#endif
 
 		if (sipdebug && option_debug > 3) 
 			ast_log(LOG_DEBUG,"Invite/replaces: Will use Replace-Call-ID : %s Fromtag: %s Totag: %s\n", replace_id, fromtag ? fromtag : "<no from tag>", totag ? totag : "<no to tag>");



More information about the svn-commits mailing list