You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Konstantin Kolinko <kn...@gmail.com> on 2011/01/18 17:19:14 UTC

Improving CGIServlet - path and args to the executable

Hi!

In 6.0.30 to fix BZ 49657 we changed the way how cgi command is built
in CGI Servlet:
http://svn.apache.org/viewvc?view=revision&revision=1004424

Earlier implementation used to build the command as a single string,
wrapping parts of it in double quotes. The new implementation uses
Runtime.exec(String[]) and passes all arguments separate from each
other as an array.

This causes regression for people using empty value for "executable"
init-param, as reported in
https://issues.apache.org/bugzilla/show_bug.cgi?id=50606

I closed BZ 50606 as INVALID but now I am changing my mind. Looking around

1) there are sites that recommend using an empty string for "executable"
http://stackoverflow.com/questions/499456/cgi-and-tomcat/500527#500527

Apparently it is to run programs that themselves are executables, as
*.exe on Windows.

2) some put in arguments for the executable, as "cmd /q /c"
http://webcache.googleusercontent.com/search?q=cache:njmdNKdXzNMJ:www.tek-tips.com/faqs.cfm%3Ffid%3D6467
(Should be http://www.tek-tips.com/faqs.cfm?fid=6467 but the original
site is inaccessible now).

I do not like to revert r1004424 and bother with quotes, nor I want to
parse "executable" into separate strings.
So I think of the following:
1. Allow empty value of "executable" init-param
2. Introduce additional init-params to explicitly specify additional arguments:
"executable-arg-1"
"executable-arg-2"
etc. starting with "1"

So cmd /q /c will be written as

<init-param>
  <param-name>executable</param-name>
  <param-value>cmd.exe</param-value>
</init-param>
<init-param>
  <param-name>executable-arg-1</param-name>
  <param-value>/q</param-value>
</init-param>
<init-param>
  <param-name>executable-arg-2</param-name>
  <param-value>/c</param-value>
</init-param>

What do you think?

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Improving CGIServlet - path and args to the executable

Posted by Mark Thomas <ma...@apache.org>.
On 18/01/2011 16:19, Konstantin Kolinko wrote:
> So I think of the following:
> 1. Allow empty value of "executable" init-param

+1. We can just drop that element from the String[]

> 2. Introduce additional init-params to explicitly specify additional arguments:
> "executable-arg-1"
> "executable-arg-2"
> etc. starting with "1"

+1. I assume you'd do this in a loop looking for executable-arg-N
starting with N=1 and incrementing until the parameter didn't exist.

> What do you think?

Go for it.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Improving CGIServlet - path and args to the executable

Posted by sebb <se...@gmail.com>.
On 18 January 2011 19:48, Konstantin Kolinko <kn...@gmail.com> wrote:
> 2011/1/18 sebb <se...@gmail.com>:
>>
>> The empty string is assumed to be "perl", according to:
>>
>
> No. Absence of this init-param is what will be "perl".
>
> Setting it explicitly overwrites the default.
>
>        if (getServletConfig().getInitParameter("executable") != null) {
>            cgiExecutable = getServletConfig().getInitParameter("executable");
>        }

I see, perhaps the docs could make this more obvious?

>>> So cmd /q /c will be written as
>>>
>>> <init-param>
>>>  <param-name>executable</param-name>
>>>  <param-value>cmd.exe</param-value>
>>> </init-param>
>>> <init-param>
>>>  <param-name>executable-arg-1</param-name>
>>>  <param-value>/q</param-value>
>>> </init-param>
>>> <init-param>
>>>  <param-name>executable-arg-2</param-name>
>>>  <param-value>/c</param-value>
>>> </init-param>
>>>
>>> What do you think?
>>
>> Ant has a nicer format:
>>
>> <exec executable="cmd">
>>    <arg value="/c"/>
>>    <arg value="ant.bat"/>
>>    <arg value="-p"/>
>> </exec>
>
> That above was a part of web.xml.  Maybe you mean "arg-1", "arg-2" etc
> (instead of "executable-arg-1")?

No, I meant that the Ant format is much easier to use, and could
perhaps be added to web.xml.

Instead of

<init-param>
 <param-name>executable</param-name>
 <param-value>cmd.exe</param-value>
</init-param>
<init-param>
 <param-name>executable-arg-1</param-name>
 <param-value>/q</param-value>
</init-param>
<init-param>
 <param-name>executable-arg-2</param-name>
 <param-value>/c</param-value>
</init-param>

you would allow:

<exec executable="cmd.exe">
   <arg value="/q"/>
   <arg value="/c"/>
</exec>

which is very much simpler

Or perhaps extend param to allow multiple values:

<init-param>
 <param-name>executable</param-name>
 <param-value>cmd.exe</param-value>
 <param-value>/q</param-value>
 <param-value>/c</param-value>
</init-param>

But maybe they would both be too hard to add to the current XML syntax.

And both assume that ordering is preserved when parsing multiple tags
with the same name.

>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Improving CGIServlet - path and args to the executable

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/1/18 sebb <se...@gmail.com>:
>
> The empty string is assumed to be "perl", according to:
>

No. Absence of this init-param is what will be "perl".

Setting it explicitly overwrites the default.

        if (getServletConfig().getInitParameter("executable") != null) {
            cgiExecutable = getServletConfig().getInitParameter("executable");
        }

>> So cmd /q /c will be written as
>>
>> <init-param>
>>  <param-name>executable</param-name>
>>  <param-value>cmd.exe</param-value>
>> </init-param>
>> <init-param>
>>  <param-name>executable-arg-1</param-name>
>>  <param-value>/q</param-value>
>> </init-param>
>> <init-param>
>>  <param-name>executable-arg-2</param-name>
>>  <param-value>/c</param-value>
>> </init-param>
>>
>> What do you think?
>
> Ant has a nicer format:
>
> <exec executable="cmd">
>    <arg value="/c"/>
>    <arg value="ant.bat"/>
>    <arg value="-p"/>
> </exec>

That above was a part of web.xml.  Maybe you mean "arg-1", "arg-2" etc
(instead of "executable-arg-1")?


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Improving CGIServlet - path and args to the executable

Posted by sebb <se...@gmail.com>.
On 18 January 2011 16:19, Konstantin Kolinko <kn...@gmail.com> wrote:
> Hi!
>
> In 6.0.30 to fix BZ 49657 we changed the way how cgi command is built
> in CGI Servlet:
> http://svn.apache.org/viewvc?view=revision&revision=1004424
>
> Earlier implementation used to build the command as a single string,
> wrapping parts of it in double quotes. The new implementation uses
> Runtime.exec(String[]) and passes all arguments separate from each
> other as an array.
>
> This causes regression for people using empty value for "executable"
> init-param, as reported in
> https://issues.apache.org/bugzilla/show_bug.cgi?id=50606
>
> I closed BZ 50606 as INVALID but now I am changing my mind. Looking around
>
> 1) there are sites that recommend using an empty string for "executable"
> http://stackoverflow.com/questions/499456/cgi-and-tomcat/500527#500527
>
> Apparently it is to run programs that themselves are executables, as
> *.exe on Windows.

The empty string is assumed to be "perl", according to:

http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html#Configuration
and
http://tomcat.apache.org/tomcat-7.0-doc/cgi-howto.html#Configuration

which says:

"executable - The of the executable to be used to run the script.
Default is perl." (sic)

BTW: s/The of/The name of/

> 2) some put in arguments for the executable, as "cmd /q /c"
> http://webcache.googleusercontent.com/search?q=cache:njmdNKdXzNMJ:www.tek-tips.com/faqs.cfm%3Ffid%3D6467
> (Should be http://www.tek-tips.com/faqs.cfm?fid=6467 but the original
> site is inaccessible now).
>
> I do not like to revert r1004424 and bother with quotes, nor I want to
> parse "executable" into separate strings.
> So I think of the following:
> 1. Allow empty value of "executable" init-param

See above.

> 2. Introduce additional init-params to explicitly specify additional arguments:
> "executable-arg-1"
> "executable-arg-2"
> etc. starting with "1"
>
> So cmd /q /c will be written as
>
> <init-param>
>  <param-name>executable</param-name>
>  <param-value>cmd.exe</param-value>
> </init-param>
> <init-param>
>  <param-name>executable-arg-1</param-name>
>  <param-value>/q</param-value>
> </init-param>
> <init-param>
>  <param-name>executable-arg-2</param-name>
>  <param-value>/c</param-value>
> </init-param>
>
> What do you think?

Ant has a nicer format:

<exec executable="cmd">
    <arg value="/c"/>
    <arg value="ant.bat"/>
    <arg value="-p"/>
</exec>

This would be tricky to fit into the existing scheme, but something
similar could perhaps be added as an alternative to the current
scheme?

I.e. leave the existing scheme (and don't bother trying to deal with
quotes), and add the new scheme for handling parameters properly.

> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org