[asterisk-bugs] [JIRA] (ASTERISK-28459) pbx: Asterisk is dropping part of a string passed to functions

Jan Blom (JIRA) noreply at issues.asterisk.org
Mon Jun 24 18:49:47 CDT 2019


    [ https://issues.asterisk.org/jira/browse/ASTERISK-28459?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=247466#comment-247466 ] 

Jan Blom commented on ASTERISK-28459:
-------------------------------------

Thanks for the pointer! The function parse_variable_name() is located in main/pbx_variables.c. 

I have made a very simple patch for the parser to honor '\' as escape character. This makes all my test cases to go through. 

{code:title=The updated function in main/pbx_variables.c}
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
{
        int parens = 0;
        int skip_next = 0;

        *offset = 0;
        *length = INT_MAX;
        *isfunc = 0;
        for (; *var; var++) {
                if (skip_next != 0) {
                        /* skip this char */
                        skip_next = 0;
                } else if (*var == '\\') {
                        skip_next = 1;
                } else  if (*var == '(') {
                        (*isfunc)++;
                        parens++;
                } else if (*var == ')') {
                        parens--;
                } else if (*var == ':' && parens == 0) {
                        *var++ = '\0';
                        sscanf(var, "%30d:%30d", offset, length);
                        return 1; /* offset:length valid */
                }
        }
        return 0;
}
{code}

Patch file has been attached to this Jira. 

> pbx: Asterisk is dropping part of a string passed to functions
> --------------------------------------------------------------
>
>                 Key: ASTERISK-28459
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-28459
>             Project: Asterisk
>          Issue Type: Bug
>      Security Level: None
>          Components: Core/PBX, Functions/General
>    Affects Versions: 16.4.0
>         Environment: CentOS Linux release 7.6 with Asterisk 16.4.0
>            Reporter: Jan Blom
>            Severity: Minor
>              Labels: patch
>         Attachments: pbx_variables.patch
>
>
> We need to pass around variables containing special characters, i.e. non-alfanumeric chars. This typically include SIP Call-Id from some vendors.
> We have so far managed to deal with all situations using quotes and escape character in accordance with https://wiki.asterisk.org/wiki/display/AST/Parameter+Quoting.
> However when having a string containing a closing parenthesis _and_ a colon, the string gets cut-off when passing it to a function. This becomes a big issue for us since this affects ODBC database calls as well as for example SQL_ESC() function. 
> Calling this dialplan results in the output below:
> {code}
> [test]
> exten => main,1,NoOp
>  same => n,Set(LOCAL(input)=1234ab)cd:efg)
>  same => n,Verbose(0,--- Test 1 ---)
>  same => n,Verbose(0,Input:    ${input})
>  same => n,Gosub(sub,1(${input}))
>  same => n,Set(LOCAL(output)=${GOSUB_RETVAL})
>  same => n,Verbose(0,Output:   ${output})
>  same => n,Verbose(0,Function: ${PASSTHRU(${input})})
>  same => n,Verbose(0,--- Test 2 ---)
>  same => n,Verbose(0,Input:    ${input})
>  same => n,Gosub(sub,1("${input}"))
>  same => n,Set(LOCAL(output)=${GOSUB_RETVAL})
>  same => n,Verbose(0,Output:   ${output})
>  same => n,Verbose(0,Function: ${PASSTHRU("${input}")})
>  same => n,Verbose(0,--- Test done ---)
>  same => n,Return
> exten => sub,1,NoOp
>  same => n,Verbose(0,In sub:   ${ARG1})
>  same => n,Return(${ARG1})
> {code}
> Result:
> {noformat}
> --- Test 1 ---
> Input:    1234ab)cd:efg
> In sub:   1234ab)cd:efg
> Output:   1234ab)cd:efg
> Function: 1234ab
> --- Test 2 ---
> Input:    1234ab)cd:efg
> In sub:   "1234ab)cd:efg"
> Output:   "1234ab)cd:efg"
> Function: "1234ab
> --- Test done ---
> {noformat}
> You can see the cut-off string returned from PASSTHRU(). We could use any function that takes a string as input and have the same result. The test shows that calling subroutines with Gosub works fine though. 
> It doesn't matter if we surround the string in quotes (the difference between Test 1 ans Test 2) or if we escape the parenthesis and/or colon in any combination with a backslash. We always get the corrupted string passed into the function. 
> We haven't been able to find any workaround to this problem. It breaks our database calling, using ODBC. 



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list