This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 213139c581 Make sure temporary files are deleted 213139c581 is described below commit 213139c581091dfa278f2ed66ed849c255d9e217 Author: remm <r...@apache.org> 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 3ae7c4c032..4e1fef7929 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 3789f89d2f..4b0d2d665b 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -137,6 +137,10 @@ <code>ExtendedAccessLogValve</code>. Based on pull request <pr>814</pr> by Dmole. (markt) </add> + <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: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org