This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 3beca8ceb8 Do not depend on Content-Length to process request bodies #
Conflicts: # webapps/docs/changelog.xml # Conflicts: #
webapps/docs/changelog.xml # Conflicts: # webapps/docs/changelog.xml
3beca8ceb8 is described below
commit 3beca8ceb8868e79de97cf742b522ff20d88de34
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Oct 28 08:39:26 2026 +0000
Do not depend on Content-Length to process request bodies
# Conflicts:
# webapps/docs/changelog.xml
# Conflicts:
# webapps/docs/changelog.xml
# Conflicts:
# webapps/docs/changelog.xml
---
java/org/apache/catalina/servlets/CGIServlet.java | 19 ++++++++++++-------
.../apache/catalina/servlets/LocalStrings.properties | 1 +
webapps/docs/changelog.xml | 4 ++++
3 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/catalina/servlets/CGIServlet.java
b/java/org/apache/catalina/servlets/CGIServlet.java
index 1ad0ea9a26..55949fce6d 100644
--- a/java/org/apache/catalina/servlets/CGIServlet.java
+++ b/java/org/apache/catalina/servlets/CGIServlet.java
@@ -1413,7 +1413,7 @@ public final class CGIServlet extends HttpServlet {
InputStream cgiOutput = null;
BufferedReader commandsStdErr = null;
Thread errReaderThread = null;
- BufferedOutputStream commandsStdIn;
+ BufferedOutputStream commandsStdIn = null;
Process proc = null;
int bufRead = -1;
@@ -1431,14 +1431,12 @@ public final class CGIServlet extends HttpServlet {
rt = Runtime.getRuntime();
proc = rt.exec(cmdAndArgs.toArray(new String[0]),
mapToStringArray(env), wd);
- String sContentLength = env.get("CONTENT_LENGTH");
-
- if (!"".equals(sContentLength)) {
- commandsStdIn = new
BufferedOutputStream(proc.getOutputStream());
+ commandsStdIn = new
BufferedOutputStream(proc.getOutputStream());
+ if (stdin != null) {
IOTools.flow(stdin, commandsStdIn);
- commandsStdIn.flush();
- commandsStdIn.close();
}
+ commandsStdIn.close();
+ commandsStdIn = null;
/*
* we want to wait for the process to exit, Process.waitFor()
is useless in our situation; see
@@ -1543,6 +1541,13 @@ public final class CGIServlet extends HttpServlet {
log.warn(sm.getString("cgiServlet.runOutputStreamFail"), ioe);
}
}
+ if (commandsStdIn != null) {
+ try {
+ commandsStdIn.close();
+ } catch (IOException ioe) {
+ log.warn(sm.getString("cgiServlet.commandsStdInFail"),
ioe);
+ }
+ }
// Close the error stream reader if used
if (commandsStdErr != null) {
try {
diff --git a/java/org/apache/catalina/servlets/LocalStrings.properties
b/java/org/apache/catalina/servlets/LocalStrings.properties
index 3e5d9fd14b..55139eb976 100644
--- a/java/org/apache/catalina/servlets/LocalStrings.properties
+++ b/java/org/apache/catalina/servlets/LocalStrings.properties
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+cgiServlet.commandsStdInFail=I/O problems closing stdin writer
cgiServlet.emptyEnvVarName=Empty environment variable name in initialisation
parameter [environment-variable-]
cgiServlet.expandCloseFail=Failed to close input stream for script at path
[{0}]
cgiServlet.expandCreateDirFail=Failed to create destination directory [{0}]
for script expansion
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e7e508a12d..ded62aebd9 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -510,6 +510,10 @@
<code>serverAuthContext.secureResponse()</code> should result in an
internal server error (500) response. (markt)
</fix>
+ <fix>
+ Do not depend on the content length being defined when processing
+ request bodies with the CGI Servlet. (csutherl)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]