[Home]

Summary:ASTERISK-14529: [patch] #exec strips too many leading and trailing quotes
Reporter:pkempgen (pkempgen)Labels:
Date Opened:2009-07-25 12:00:50Date Closed:2009-09-17 12:18:23
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Core/Configuration
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 20090726__issue15583.diff.txt
( 1) 20090726__issue15583-1.4.diff.txt
( 2) 20090726__issue15583-1.4-3.diff.txt
( 3) 20090726__issue15583-1.4-4.diff.txt
( 4) extensions.conf
Description:#exec (main/config.c) strips leading and trailing quotes ("<>)
from the command which is a good thing but it strips too many.

Affects 1.4 and probably 1.6.* and trunk as well.

****** STEPS TO REPRODUCE ******

[exectest]

exten => 1,1,NoOp(Expecting 2 args: 1-2)
#exec perl -e 'print "exten => 1,n,NoOp( Received ".@ARGV." args: ".join("-", @ARGV).")\n"' -- 1 2
; output:    NoOp( Received 2 args: 1-2)   --OK

exten => 2,1,NoOp(Expecting 3 args: 1-2-)
#exec perl -e 'print "exten => 2,n,NoOp( Received ".@ARGV." args: ".join("-", @ARGV).")\n"' -- 1 2 ''
; output:    NoOp( Received 3 args: 1-2-)  --OK

exten => 3,1,NoOp(Expecting 3 args: 1-2-)
#exec perl -e 'print "exten => 3,n,NoOp( Received ".@ARGV." args: ".join("-", @ARGV).")\n"' -- 1 2 ""
; output:    NoOp( Received 2 args: 1-2)   --#FAIL#

exten => 4,1,NoOp(Expecting 3 args: 1-2-)
#exec "perl -e 'print "exten => 4,n,NoOp( Received ".@ARGV." args: ".join("-", @ARGV).")\n"' -- 1 2 """
; output:    NoOp( Received 2 args: 1-2)   --#FAIL#

exten => 5,1,NoOp(Expecting 3 args: 1-2-)
#exec "perl -e 'print "exten => 5,n,NoOp( Received ".@ARGV." args: ".join("-", @ARGV).")\n"' -- 1 2 "" "
; output:    NoOp( Received 3 args: 1-2-)  --OK

exten => 6,1,NoOp(Expecting 2 args: 1-2)
#exec perl -e 'print "exten => 6,n,NoOp( Received ".@ARGV." args: ".join("-", @ARGV).")\n"' -- "1" "2"
; output:                                  --#FAIL# (does not execute)

exten => 7,1,NoOp(Expecting 2 args: 1-2)
#exec "perl -e 'print "exten => 7,n,NoOp( Received ".@ARGV." args: ".join("-", @ARGV).")\n"' -- "1" "2""
; output:                                  --#FAIL# (does not execute)


****** ADDITIONAL INFORMATION ******

Solution:
Strip no more than 1 leading character and no more than 1 trailing
character and only do so if both are equal.

Workaround:
Enclose the command in double quotes and add whitespace (e.g. a
blank character) just before the closing quote.

Since an easy workaround is available I'm fine with a WONTFIX
but it's up to you.
Comments:By: pkempgen (pkempgen) 2009-07-25 12:41:34

> Solution:
> Strip no more than 1 leading character and no more than 1 trailing
> character and only do so if both are equal.

Correction: In this case "equal" means that '<' matches '>'
(and '"' matches '"' of course).

By: Tilghman Lesher (tilghman) 2009-07-25 12:52:07

"Affects 1.4 and probably 1.6.* and trunk as well."

That's not a good assumption.  Trunk and 1.6.* have radically different configurations that unquote differently than 1.4.  Please test with one or more of those versions.

I'm still not inclined to change this for 1.4, but it's incorrect to assume that 1.6 is the same as 1.4 in this respect.

By: pkempgen (pkempgen) 2009-07-25 13:35:22

My assumption was based on a diff (from 1.4 to 1.6.2 or trunk) of
what I think is the relevant code.

I don't find anything that should cause a different behavior.



By: pkempgen (pkempgen) 2009-07-25 18:42:37

Confirmed in 1.6.1 rev. 208852.

By: Tilghman Lesher (tilghman) 2009-07-26 13:47:50

Could you specify a command which strips too much?  And also post an example of your workaround?

By: pkempgen (pkempgen) 2009-07-26 16:11:22

Examples 3, 4, 6 and 7 in "Steps To Reproduce" are commands where it
strips too many quotes. Example 5 is the workaround.

By: Tilghman Lesher (tilghman) 2009-07-26 22:11:34

Okay, the documentation states that you can execute a program or a script.  It makes no mention of passing arguments to that program or script, and there's no example of such.

Nevertheless, it probably should be fixed.

By: Tilghman Lesher (tilghman) 2009-07-26 22:32:23

This patch will allow:

using '<' and '>' to delimit the executable (really meant for '#include <foo.conf>') OR using NO quotes to surround the arguments (and it will be passed blindly to /bin/sh) OR using quotes to surround the arguments (and the argument will be dequoted per normal rules, backslash being the escape character).

I think that's a sane solution that should be backwards compatible.

By: pkempgen (pkempgen) 2009-07-27 07:00:58

20090726__issue15583.diff.txt seems to be made against 1.4 so I
tested against 1.4. Does not work. The #execs are executed but
Asterisk does not load the output.
I have uploaded a modified version (20090726__issue15583-1.4.diff.txt)
of your patch (+ cur = c;).
It fixes the issue for 1.4.
EDIT: Wait. I spoke too soon.



By: pkempgen (pkempgen) 2009-07-27 08:07:24

Tastcases attached (extensions.conf).

By: pkempgen (pkempgen) 2009-07-27 08:11:22

Your patch did not remove the leading '<'. I have now uploaded a modified version (20090726__issue15583-1.4-3.diff.txt) of your patch. All of the test cases (see extensions.conf attachment) work fine in 1.4.

By: pkempgen (pkempgen) 2009-07-27 08:51:20

20090726__issue15583-1.4-4.diff.txt adds some examples to
the documentation in configs/extensions.conf.sample.

By: Digium Subversion (svnbot) 2009-09-16 18:23:37

Repository: asterisk
Revision: 219023

U   branches/1.4/configs/extensions.conf.sample
U   branches/1.4/main/config.c

------------------------------------------------------------------------
r219023 | tilghman | 2009-09-16 18:23:36 -0500 (Wed, 16 Sep 2009) | 8 lines

Properly deal with quotes in the arguments of '#exec' includes.
(closes issue ASTERISK-14529)
Reported by: pkempgen
Patches:
      20090726__issue15583.diff.txt uploaded by tilghman (license 14)
      20090726__issue15583-1.4-4.diff.txt uploaded by pkempgen (license 169)
Tested by: pkempgen

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

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

By: Digium Subversion (svnbot) 2009-09-16 18:43:55

Repository: asterisk
Revision: 219061

_U  trunk/
U   trunk/configs/extensions.conf.sample
U   trunk/main/config.c

------------------------------------------------------------------------
r219061 | tilghman | 2009-09-16 18:43:55 -0500 (Wed, 16 Sep 2009) | 15 lines

Merged revisions 219023 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
 r219023 | tilghman | 2009-09-16 18:21:53 -0500 (Wed, 16 Sep 2009) | 8 lines
 
 Properly deal with quotes in the arguments of '#exec' includes.
 (closes issue ASTERISK-14529)
  Reported by: pkempgen
  Patches:
        20090726__issue15583.diff.txt uploaded by tilghman (license 14)
        20090726__issue15583-1.4-4.diff.txt uploaded by pkempgen (license 169)
  Tested by: pkempgen
........

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

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

By: Digium Subversion (svnbot) 2009-09-16 18:53:52

Repository: asterisk
Revision: 219062

_U  branches/1.6.1/
U   branches/1.6.1/configs/extensions.conf.sample
U   branches/1.6.1/main/config.c

------------------------------------------------------------------------
r219062 | tilghman | 2009-09-16 18:53:52 -0500 (Wed, 16 Sep 2009) | 22 lines

Merged revisions 219061 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r219061 | tilghman | 2009-09-16 18:42:12 -0500 (Wed, 16 Sep 2009) | 15 lines
 
 Merged revisions 219023 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r219023 | tilghman | 2009-09-16 18:21:53 -0500 (Wed, 16 Sep 2009) | 8 lines
   
   Properly deal with quotes in the arguments of '#exec' includes.
   (closes issue ASTERISK-14529)
    Reported by: pkempgen
    Patches:
          20090726__issue15583.diff.txt uploaded by tilghman (license 14)
          20090726__issue15583-1.4-4.diff.txt uploaded by pkempgen (license 169)
    Tested by: pkempgen
 ........
................

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

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

By: Digium Subversion (svnbot) 2009-09-16 18:54:01

Repository: asterisk
Revision: 219063

_U  branches/1.6.2/
U   branches/1.6.2/configs/extensions.conf.sample
U   branches/1.6.2/main/config.c

------------------------------------------------------------------------
r219063 | tilghman | 2009-09-16 18:54:00 -0500 (Wed, 16 Sep 2009) | 22 lines

Merged revisions 219061 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r219061 | tilghman | 2009-09-16 18:42:12 -0500 (Wed, 16 Sep 2009) | 15 lines
 
 Merged revisions 219023 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r219023 | tilghman | 2009-09-16 18:21:53 -0500 (Wed, 16 Sep 2009) | 8 lines
   
   Properly deal with quotes in the arguments of '#exec' includes.
   (closes issue ASTERISK-14529)
    Reported by: pkempgen
    Patches:
          20090726__issue15583.diff.txt uploaded by tilghman (license 14)
          20090726__issue15583-1.4-4.diff.txt uploaded by pkempgen (license 169)
    Tested by: pkempgen
 ........
................

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

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

By: Digium Subversion (svnbot) 2009-09-16 18:54:09

Repository: asterisk
Revision: 219064

_U  branches/1.6.0/
U   branches/1.6.0/configs/extensions.conf.sample
U   branches/1.6.0/main/config.c

------------------------------------------------------------------------
r219064 | tilghman | 2009-09-16 18:54:09 -0500 (Wed, 16 Sep 2009) | 22 lines

Merged revisions 219061 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r219061 | tilghman | 2009-09-16 18:42:12 -0500 (Wed, 16 Sep 2009) | 15 lines
 
 Merged revisions 219023 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r219023 | tilghman | 2009-09-16 18:21:53 -0500 (Wed, 16 Sep 2009) | 8 lines
   
   Properly deal with quotes in the arguments of '#exec' includes.
   (closes issue ASTERISK-14529)
    Reported by: pkempgen
    Patches:
          20090726__issue15583.diff.txt uploaded by tilghman (license 14)
          20090726__issue15583-1.4-4.diff.txt uploaded by pkempgen (license 169)
    Tested by: pkempgen
 ........
................

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

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

By: pkempgen (pkempgen) 2009-09-16 20:21:33

I believe 20090726__issue15583.diff.txt instead of
20090726__issue15583-1.4-3.diff.txt was committed by accident.

By: Tilghman Lesher (tilghman) 2009-09-17 12:01:03

Why do you believe this?  I actually committed -4, but I noted the original, because the patches were the combination of efforts of two different people.