enum.c did not handle regex backtraces correctly. The '\1' in the regex is a backreference that requires a pattern match to be inserted. The way the code used to work is that it would find the backreference and insert the entire input string minus the '+'. This is incorrect. The regexec() function takes in a variable called pmatch which is an array of structs containing the start and end indexes for each backreference substring. The original code actually passed the pmatch array pointer into regexec but never did anything with it. Now when a backtrace is found, the backtrace number is looked up in the pmatch array and the correct substring is inserted.
(closes issue #14576)
Reported by: chris-mac
Review: http://reviewboard.digium.com/r/187/
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@180532 65c4cc65-6c06-0410-ace0-fbb531ad65f3
ast_log(LOG_WARNING,"Regex delimiter error (on \"%s\").\n",regexp);
if((delim2==NULL)||(regexp[regexp_len-1]!=delim)){/* is the second delimiter found, and is the end of the regexp a delimiter */
ast_log(LOG_WARNING,"Regex delimiter error (on \"%s\").\n",regexp);
return-1;
}elseif(strchr((delim2+1),delim)==NULL){/* if the second delimiter is found, make sure there is a third instance. this could be the end one instead of the middle */
ast_log(LOG_WARNING,"Regex delimiter error (on \"%s\").\n",regexp);
return-1;
}
pattern=regexp+1;
*delim2=0;
subst=delim2+1;
regexp[regexp_len-1]=0;
pattern=regexp+1;/* pattern is the regex without the begining and ending delimiter */
*delim2=0;/* zero out the middle delimiter */
subst=delim2+1;/* dst substring is everything after the second delimiter. */
regexp[regexp_len-1]=0;/* zero out the last delimiter */