This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 0f6b8ed6af Make sure temporary files are deleted
0f6b8ed6af is described below
commit 0f6b8ed6afc8f7a512d0e3399b80935b955af9c2
Author: remm <[email protected]>
AuthorDate: Wed Feb 26 19:34:47 2025 +0100
Make sure temporary files are deleted
The API forces catching exceptions to delete the temporary file.
Also log a warning if delete fails.
---
java/org/apache/catalina/servlets/DefaultServlet.java | 11 ++++++++++-
java/org/apache/catalina/servlets/LocalStrings.properties | 1 +
webapps/docs/changelog.xml | 4 ++++
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java
b/java/org/apache/catalina/servlets/DefaultServlet.java
index c58ce2b5b0..cdaa6bdf92 100644
--- a/java/org/apache/catalina/servlets/DefaultServlet.java
+++ b/java/org/apache/catalina/servlets/DefaultServlet.java
@@ -660,7 +660,9 @@ public class DefaultServlet extends HttpServlet {
}
}
if (tempContentFile != null) {
- tempContentFile.delete();
+ if (!tempContentFile.delete()) {
+ log(sm.getString("defaultServlet.deleteTempFileFailed",
tempContentFile.getAbsolutePath()));
+ }
}
}
}
@@ -715,6 +717,13 @@ public class DefaultServlet extends HttpServlet {
randAccessContentFile.write(transferBuffer, 0,
numBytesRead);
}
}
+
+ } catch (IOException | RuntimeException | Error e) {
+ // This has to be done this way to be able to close the file
without changing the method signature
+ if (!contentFile.delete()) {
+ log(sm.getString("defaultServlet.deleteTempFileFailed",
contentFile.getAbsolutePath()));
+ }
+ throw e;
}
return contentFile;
diff --git a/java/org/apache/catalina/servlets/LocalStrings.properties
b/java/org/apache/catalina/servlets/LocalStrings.properties
index b869d0819d..d2e6a16c33 100644
--- a/java/org/apache/catalina/servlets/LocalStrings.properties
+++ b/java/org/apache/catalina/servlets/LocalStrings.properties
@@ -43,6 +43,7 @@ cgiServlet.runStdErrFail=I/O problems with stderr
defaultServlet.blockExternalEntity=Blocked access to external entity with
publicId [{0}] and systemId [{0}]
defaultServlet.blockExternalEntity2=Blocked access to external entity with
name [{0}], publicId [{1}], baseURI [{2}] and systemId [{3}]
defaultServlet.blockExternalSubset=Blocked access to external subset with name
[{0}] and baseURI [{1}]
+defaultServlet.deleteTempFileFailed=Failed to delete temporary file [{0}] used
for partial PUT
defaultServlet.directory.parent=Up To [{0}]
defaultServlet.directory.title=Directory Listing For [{0}]
defaultServlet.missingResource=The requested resource [{0}] is not available
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 15cefdf8b4..22e18dd546 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -130,6 +130,10 @@
so that reflection is not used unless required. The checks for whether
the file system is case sensitive or not have been removed. (markt)
</fix>
+ <fix>
+ Avoid scenarios where temporary files used for partial PUT would not
+ be deleted. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]