Index: pbx/pbx_config.c =================================================================== --- pbx/pbx_config.c (revision 171963) +++ pbx/pbx_config.c (working copy) @@ -1403,6 +1403,39 @@ return 0; } +static char *pbx_strsep(char **destructible, const char *delim) +{ + int paren = 0, square = 0, quote = 0; + char *res = *destructible; + for (; destructible && *destructible && **destructible; (*destructible)++) { + if (**destructible == '(' && !strchr(delim, '(')) { + paren++; + } else if (**destructible == ')' && !strchr(delim, ')')) { + if (paren) { + paren--; + } + } else if (**destructible == '[' && !strchr(delim, '[')) { + square++; + } else if (**destructible == ']' && !strchr(delim, ']')) { + if (square) { + square--; + } + } else if (**destructible == '"' && !strchr(delim, '"')) { + quote = quote ? 0 : 1; + } else if (**destructible == '\\' && !strchr(delim, '\\')) { + (*destructible)++; + } else if (strchr(delim, **destructible) && !paren && !quote && !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 +1521,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: @@ -1496,7 +1529,7 @@ *cidmatch++ = '\0'; ast_shrink_phone_number(cidmatch); } - pri = S_OR(strsep(&stringp, ","), ""); + pri = S_OR(pbx_strsep(&stringp, ","), ""); pri = ast_skip_blanks(pri); pri = ast_trim_blanks(pri); if ((label = strchr(pri, '('))) { Index: main/pbx.c =================================================================== --- main/pbx.c (revision 171963) +++ main/pbx.c (working copy) @@ -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++; }