tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets CGIServlet.java
Date Sat, 17 Apr 2004 22:53:26 GMT
markt       2004/04/17 15:53:26

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        CGIServlet.java
  Log:
  Fix bug 19545. CGI issues with CONTENT_LENGTH namely:
  - CONTENT_LENGTH was recalculated after script had been executed and hence had no effect
  - Parameters were being sent to the script twice
  Patch supplied by artonx@yahoo.co.jp (with some minor mods)
  
  Revision  Changes    Path
  1.21      +25 -29    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java
  
  Index: CGIServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- CGIServlet.java	17 Apr 2004 20:01:19 -0000	1.20
  +++ CGIServlet.java	17 Apr 2004 22:53:26 -0000	1.21
  @@ -62,6 +62,7 @@
   
   package org.apache.catalina.servlets;
   
  +import java.io.ByteArrayOutputStream;
   import java.io.File;
   import java.io.FileOutputStream;
   import java.io.BufferedWriter;
  @@ -1689,26 +1690,23 @@
               command.append(cmdAndArgs.toString());
               cmdAndArgs = command;
   
  -            rt = Runtime.getRuntime();
  -            proc = rt.exec(cmdAndArgs.toString(), hashToStringArray(env), wd);
  -
               String sContentLength = (String) env.get("CONTENT_LENGTH");
  +            ByteArrayOutputStream contentStream = null;
               if(!"".equals(sContentLength)) {
  -                commandsStdIn = new BufferedOutputStream(proc.getOutputStream());
                   byte[] content = new byte[Integer.parseInt(sContentLength)];
  -
                   int lenRead = stdin.read(content);
  -
  +                contentStream = new ByteArrayOutputStream(
  +                        Integer.parseInt(sContentLength));
                   if ("POST".equals(env.get("REQUEST_METHOD"))) {
                       String paramStr = getPostInput(params);
                       if (paramStr != null) {
                           byte[] paramBytes = paramStr.getBytes();
  -                        commandsStdIn.write(paramBytes);
  +                        contentStream.write(paramBytes);
   
                           int contentLength = paramBytes.length;
                           if (lenRead > 0) {
                               String lineSep = System.getProperty("line.separator");
  -                            commandsStdIn.write(lineSep.getBytes());
  +                            contentStream.write(lineSep.getBytes());
                               contentLength = lineSep.length() + lenRead;
                           }
                           env.put("CONTENT_LENGTH", new Integer(contentLength));
  @@ -1716,9 +1714,17 @@
                   }
   
                   if (lenRead > 0) {
  -                    commandsStdIn.write(content, 0, lenRead);
  +                    contentStream.write(content, 0, lenRead);
                   }
  +                contentStream.close();
  +            }
   
  +            rt = Runtime.getRuntime();
  +            proc = rt.exec(cmdAndArgs.toString(), hashToStringArray(env), wd);
  +
  +            if(contentStream != null) {
  +                commandsStdIn = new BufferedOutputStream(proc.getOutputStream());
  +                proc.getOutputStream().write(contentStream.toByteArray());
                   commandsStdIn.flush();
                   commandsStdIn.close();
               }
  @@ -1842,37 +1848,27 @@
           protected String getPostInput(Hashtable params) {
               String lineSeparator = System.getProperty("line.separator");
               Enumeration paramNames = params.keys();
  -            StringBuffer postInput = new StringBuffer("");
               StringBuffer qs = new StringBuffer("");
               if (paramNames != null && paramNames.hasMoreElements()) {
                   while (paramNames.hasMoreElements()) {
                       String k = (String) paramNames.nextElement();
                       String v = params.get(k).toString();
                       if ((k.indexOf("=") < 0) && (v.indexOf("=") < 0)) {
  -                        postInput.append(k);
                           qs.append(k);
  -                        postInput.append("=");
                           qs.append("=");
  -                        postInput.append(v);
                           qs.append(v);
  -                        postInput.append(lineSeparator);
                           qs.append("&");
                       }
                   }
               }
               if (qs.length() > 0) {
  -                qs.append(lineSeparator);
  -                return qs.append(postInput.toString()).toString();
  +                // Remove last "&"
  +                qs.setLength(qs.length() - 1);
  +                return qs.toString();
               } else {
                   return null;
               }
           }
  -
  -
  -
       } //class CGIRunner
  -
  -
  -
   
   } //class CGIServlet
  
  
  

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


Mime
View raw message