[asterisk-commits] tilghman: trunk r173311 - in /trunk: main/pbx.c pbx/pbx_config.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 3 18:43:53 CST 2009


Author: tilghman
Date: Tue Feb  3 18:43:52 2009
New Revision: 173311

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=173311
Log:
Ensure that commas placed in the middle of extension character classes do not
interfere with correct parsing of the extension.  Also, if an unterminated
character class DOES make its way into the pbx core (through some other
method), ensure that it does not crash Asterisk.
(closes issue #14362)
 Reported by: Nick_Lewis
 Patches: 
       20090129__bug14362.diff.txt uploaded by Corydon76 (license 14)
 Tested by: Corydon76

Modified:
    trunk/main/pbx.c
    trunk/pbx/pbx_config.c

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/pbx.c?view=diff&rev=173311&r1=173310&r2=173311
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Tue Feb  3 18:43:52 2009
@@ -1900,6 +1900,9 @@
 						*s2++ = s3;
 					}
 					s1++; s1++;
+				} else if (*s1 == '\0') {
+					ast_log(LOG_WARNING, "A matching ']' was not found for '[' in pattern string '%s'\n", extenbuf);
+					break;
 				} else {
 					*s2++ = *s1++;
 				}

Modified: trunk/pbx/pbx_config.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/pbx/pbx_config.c?view=diff&rev=173311&r1=173310&r2=173311
==============================================================================
--- trunk/pbx/pbx_config.c (original)
+++ trunk/pbx/pbx_config.c Tue Feb  3 18:43:52 2009
@@ -1403,6 +1403,36 @@
 	return 0;
 }
 
+/*!\note Protect against misparsing based upon commas in the middle of fields
+ * like character classes.  We've taken steps to permit pretty much every other
+ * printable character in a character class, so properly handling a comma at
+ * this level is a natural extension.  This is almost like the standard
+ * application parser in app.c, except that it handles square brackets. */
+static char *pbx_strsep(char **destructible, const char *delim)
+{
+	int square = 0;
+	char *res = *destructible;
+	for (; destructible && *destructible && **destructible; (*destructible)++) {
+		if (**destructible == '[' && !strchr(delim, '[')) {
+			square++;
+		} else if (**destructible == ']' && !strchr(delim, ']')) {
+			if (square) {
+				square--;
+			}
+		} else if (**destructible == '\\' && !strchr(delim, '\\')) {
+			(*destructible)++;
+		} else if (strchr(delim, **destructible) && !square) {
+			**destructible = '\0';
+			(*destructible)++;
+			break;
+		}
+	}
+	if (destructible && *destructible && **destructible == '\0') {
+		*destructible = NULL;
+	}
+	return res;
+}
+
 static int pbx_load_config(const char *config_file)
 {
 	struct ast_config *cfg;
@@ -1488,7 +1518,7 @@
 					continue;
 				}
 
-				ext = S_OR(strsep(&stringp, ","), "");
+				ext = S_OR(pbx_strsep(&stringp, ","), "");
 				pbx_substitute_variables_helper(NULL, ext, realext, sizeof(realext) - 1);
 				ast_copy_string(lastextension, realext, sizeof(lastextension));
 process_extension:




More information about the asterisk-commits mailing list