From: kkolinko Date: Thu, 20 Jan 2011 17:43:35 +0000 (+0000) Subject: Fix http://issues.apache.org/bugzilla/show_bug.cgi?id=50606 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f113fb5f6c212bce86fc29ac1933a57a375ed19c;p=tomcat7.0 Fix issues.apache.org/bugzilla/show_bug.cgi?id=50606 Improve CGIServlet: Provide support for specifying empty value for the executable init-param. Provide support for explicit additional arguments for the executable. Those were broken when implementing fix for bug 49657 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1061412 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/servlets/CGIServlet.java b/java/org/apache/catalina/servlets/CGIServlet.java index 5da05f744..993184024 100644 --- a/java/org/apache/catalina/servlets/CGIServlet.java +++ b/java/org/apache/catalina/servlets/CGIServlet.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; import java.util.Hashtable; +import java.util.List; import java.util.Locale; import java.util.StringTokenizer; import java.util.Vector; @@ -257,7 +258,10 @@ public final class CGIServlet extends HttpServlet { /** the executable to use with the script */ private String cgiExecutable = "perl"; - + + /** additional arguments for the executable */ + private List cgiExecutableArgs = null; + /** the encoding to use for parameters */ private String parameterEncoding = System.getProperty("file.encoding", "UTF-8"); @@ -309,6 +313,19 @@ public final class CGIServlet extends HttpServlet { cgiExecutable = getServletConfig().getInitParameter("executable"); } + if (getServletConfig().getInitParameter("executable-arg-1") != null) { + List args = new ArrayList(); + for (int i = 1;; i++) { + String arg = getServletConfig().getInitParameter( + "executable-arg-" + i); + if (arg == null) { + break; + } + args.add(arg); + } + cgiExecutableArgs = args; + } + if (getServletConfig().getInitParameter("parameterEncoding") != null) { parameterEncoding = getServletConfig().getInitParameter("parameterEncoding"); } @@ -1578,20 +1595,21 @@ public final class CGIServlet extends HttpServlet { Process proc = null; int bufRead = -1; - String[] cmdAndArgs = new String[params.size() + 2]; - - cmdAndArgs[0] = cgiExecutable; - - cmdAndArgs[1] = command; - - //create query arguments - for (int i=0; i < params.size(); i++) { - cmdAndArgs[i + 2] = params.get(i); + List cmdAndArgs = new ArrayList(); + if (cgiExecutable.length() != 0) { + cmdAndArgs.add(cgiExecutable); + } + if (cgiExecutableArgs != null) { + cmdAndArgs.addAll(cgiExecutableArgs); } + cmdAndArgs.add(command); + cmdAndArgs.addAll(params); try { rt = Runtime.getRuntime(); - proc = rt.exec(cmdAndArgs, hashToStringArray(env), wd); + proc = rt.exec( + cmdAndArgs.toArray(new String[cmdAndArgs.size()]), + hashToStringArray(env), wd); String sContentLength = env.get("CONTENT_LENGTH"); diff --git a/webapps/docs/cgi-howto.xml b/webapps/docs/cgi-howto.xml index c84e0b55c..8f4eb0b63 100644 --- a/webapps/docs/cgi-howto.xml +++ b/webapps/docs/cgi-howto.xml @@ -80,9 +80,14 @@ The default cgiPathPrefix is WEB-INF/cgi
  • debug - Debugging detail level for messages logged by this servlet. Default 0.
  • executable - The of the executable to be used to -run the script. Default is perl.
  • +run the script. You may explicitly set this parameter to be an empty string +if your script is itself executable (e.g. an exe file). Default is +perl. +
  • executable-arg-1, executable-arg-2, +and so on - additional arguments for the executable. These precede the +CGI script name. By default there are no additional arguments.
  • parameterEncoding - Name of the parameter encoding -to be used with the GCI servlet. Default is +to be used with the CGI servlet. Default is System.getProperty("file.encoding","UTF-8").
  • passShellEnvironment - Should the shell environment variables (if any) be passed to the CGI script? Default is diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 2827e8c87..613a950c0 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -148,6 +148,12 @@ 50601: Code clean-up. Patch provided by sebb. (markt) + + 50606: Improve CGIServlet: Provide support for specifying + empty value for the executable init-param. Provide support + for explicit additional arguments for the executable. Those were + broken when implementing fix for bug 49657. (kkolinko) +