Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't disable error page support unless debug is set to 10 or more.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1689918 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jul 8, 2015
1 parent fabad84 commit e224c02
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
8 changes: 6 additions & 2 deletions conf/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@
<!-- to 5 where 0 means no logging and 5 means -->
<!-- maximum logging. Values of 10 or more mean -->
<!-- maximum logging plus debug info added to the -->
<!-- HTTP response. Note that any value of 10 or -->
<!-- more has the same effect. [0] -->
<!-- HTTP response. If an error occurs and debug is -->
<!-- 10 or more the standard error page mechanism -->
<!-- will be disabled and a response body with -->
<!-- debug information will be produced. Note that -->
<!-- any value of 10 or more has the same effect as -->
<!-- a value of 10. [0] -->
<!-- -->
<!-- fileEncoding Encoding to be used to read static resources -->
<!-- [platform default] -->
Expand Down
46 changes: 40 additions & 6 deletions java/org/apache/catalina/servlets/CGIServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ public final class CGIServlet extends HttpServlet {
/**
* The debugging detail level for this servlet. Useful values range from 0
* to 5 where 0 means no logging and 5 means maximum logging. Values of 10
* or more mean maximum logging plus debug info added to the HTTP response.
* Note that any value of 10 or more has the same effect.
* or more mean maximum logging and debug info added to the HTTP response.
* If an error occurs and debug is 10 or more the standard error page
* mechanism will be disabled and a response body with debug information
* will be produced. Note that any value of 10 or more has the same effect
* as a value of 10.
*/
private int debug = 0;

Expand Down Expand Up @@ -586,7 +589,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res)
cgi.setResponse(res);
cgi.run();
} else {
res.setStatus(404);
if (setStatus(res, 404)) {
return;
}
}

if (debug >= 10) {
Expand Down Expand Up @@ -626,6 +631,29 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res)
}


/*
* Behaviour depends on the status code and the value of debug.
*
* Status < 400 - Always calls setStatus. Returns false. CGI servlet will
* provide the response body.
* Status >= 400 - Depends on debug
* debug < 10 - Calls sendError(status), returns true. Standard error
* page mechanism will provide the response body.
* debug >= 10 - Calls setStatus(status), return false. CGI servlet will
* provide the response body.
*/
private boolean setStatus(HttpServletResponse response, int status) throws IOException {

if (status >= HttpServletResponse.SC_BAD_REQUEST && debug < 10) {
response.sendError(status);
return true;
} else {
response.setStatus(status);
return false;
}
}


/**
* Encapsulates the CGI environment and rules to derive
* that environment from the servlet container and request information.
Expand Down Expand Up @@ -1638,6 +1666,12 @@ public void run () {
cgiHeaderReader =
new BufferedReader(new InputStreamReader(cgiHeaderStream));

// Need to be careful here. If sendError() is called the
// response body should be provided by the standard error page
// process. But, if the output of the CGI process isn't read
// then that process can hang.
boolean skipBody = false;

while (isRunning) {
try {
//set headers
Expand All @@ -1648,14 +1682,14 @@ public void run () {
log("runCGI: addHeader(\"" + line + "\")");
}
if (line.startsWith("HTTP")) {
response.setStatus(getSCFromHttpStatusLine(line));
skipBody = setStatus(response, getSCFromHttpStatusLine(line));
} else if (line.indexOf(":") >= 0) {
String header =
line.substring(0, line.indexOf(":")).trim();
String value =
line.substring(line.indexOf(":") + 1).trim();
if (header.equalsIgnoreCase("status")) {
response.setStatus(getSCFromCGIStatusHeader(value));
skipBody = setStatus(response, getSCFromCGIStatusHeader(value));
} else {
response.addHeader(header , value);
}
Expand All @@ -1671,7 +1705,7 @@ public void run () {
cgiOutput = proc.getInputStream();

try {
while ((bufRead = cgiOutput.read(bBuf)) != -1) {
while (!skipBody && (bufRead = cgiOutput.read(bBuf)) != -1) {
if (debug >= 4) {
log("runCGI: output " + bufRead +
" bytes of data");
Expand Down
6 changes: 4 additions & 2 deletions webapps/docs/cgi-howto.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ directory being used as the search path. The recommended value is
<li><strong>debug</strong> - Debugging detail level for messages logged
by this servlet. Useful values range from 0 to 5 where 0 means no logging and 5
means maximum logging. Values of 10 or more mean maximum logging plus debug info
added to the HTTP response. Note that any value of 10 or more has the same
effect. Default is <code>0</code>.</li>
added to the HTTP response. If an error occurs and debug is 10 or more the
standard error page mechanism will be disabled and a response body with debug
information will be produced. Note that any value of 10 or more has the same
effect as a value of 10. Default is <code>0</code>.</li>
<li><strong>executable</strong> - The of the executable to be used to
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
Expand Down

0 comments on commit e224c02

Please sign in to comment.