[Home]

Summary:ASTERISK-05226: [patch] Incorrect parsing of IF, SWITCH and WHILE operators argument.
Reporter:Sergey Okhapkin (sokhapkin)Labels:
Date Opened:2005-10-03 14:22:31Date Closed:2008-01-15 15:50:40.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:PBX/pbx_ael
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) pbx_ael.c.cvs.diff
( 1) pbx_ael.c.diff
( 2) pbx_ael.c.diff-else
Description:To find the argument of these operators pbx_ael.c uses the following code:

if ((*args == '(') && (c = strchr(args, ')'))) {

The code sets "c" to incorrect "end of argument" location if the argument contains ")" character like in

if(${COLLERID(number)} = "1234567")
        noop(blah);

the "if" operator is translated (incorrectly) into:

    3. GotoIf($[ ${CALLERID(number ]?4:5)         [pbx_ael]
    4. Set(}=$[ 1234567)        noop(blah) ])            [pbx_ael]
    5. NoOp(Finish if-stdexten-3)                 [pbx_ael]

Comments:By: Sergey Okhapkin (sokhapkin) 2005-10-04 08:16:22

Attached trivial fix resolves the problem. The diff is against 1.2-beta1 release but applies clean to CVS HEAD also.

By: Sergey Okhapkin (sokhapkin) 2005-10-05 12:04:03

Added patch wich fixes parsing of operator "else" when "if" operator body contains braces like in

if(condition) {
   a=${b};
} else
   a=0;

By: Sergey Okhapkin (sokhapkin) 2005-10-09 15:42:16

I made a new patch for pbx_ael.c. The patch is against CVS HEAD, includes all changes from previous 2 patches and adds CLI to pbx_ael module.

By: Russell Bryant (russell) 2005-10-11 19:03:42

Is there a reason to use argument_end() as opposed to just calling strrchr(), as opposed to strchr(), to find the last closing paren?



By: Sergey Okhapkin (sokhapkin) 2005-10-11 19:18:45

No, we can't use strrchr(), we have to check brackets nesting level. strrchr() will not find end of "if" in

if(asd()) a=qwe();

Even

if(asd()) {
  a=qwe();
}

will not work - AEL removes all linefeeds before parsing, it parses from current character position till the end of context.

By: Russell Bryant (russell) 2005-10-11 19:43:05

ok, I probably should have just read the code instead of just asking.  :)

By: Mark Spencer (markster) 2005-10-12 16:58:41

Do you have a disclaimer on file so we can merge these changes?  Thanks!

By: Sergey Okhapkin (sokhapkin) 2005-10-12 17:04:43

markster: No, I didn't file a disclaimer. Where can I get the disclaimer form?

By: twisted (twisted) 2005-10-12 17:33:36

http://www.digium.com/index.php?menu=bugguidelines   almost at the bottom.  You have your choice of disclaimers.

By: Sergey Okhapkin (sokhapkin) 2005-10-13 07:56:07

Disclaimer sent.

By: Mark Spencer (markster) 2005-10-13 11:41:57

Fixed in CVS head, thanks for your contribution!

By: Digium Subversion (svnbot) 2008-01-15 15:50:40.000-0600

Repository: asterisk
Revision: 6756

U   trunk/pbx/pbx_ael.c

------------------------------------------------------------------------
r6756 | markster | 2008-01-15 15:50:40 -0600 (Tue, 15 Jan 2008) | 2 lines

Fix ael if, while, else (bug ASTERISK-5226)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=6756