struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [06/50] [abbrv] struts git commit: WW-4583 JakartaStreamMultiPartRequest fails on short file name and on empty file input
Date Fri, 15 Jul 2016 13:18:33 GMT
WW-4583 JakartaStreamMultiPartRequest fails on short file name and on empty file input


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/b84fd6fe
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/b84fd6fe
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/b84fd6fe

Branch: refs/heads/master
Commit: b84fd6fe0ca1d159da831df8444ee18bb9727e1b
Parents: 6fd37d8
Author: Aleksandr Mashchenko <amashchenko@apache.org>
Authored: Wed Jan 6 19:24:56 2016 +0200
Committer: Lukasz Lenart <lukasz.lenart@gmail.com>
Committed: Tue Jan 19 16:18:00 2016 +0100

----------------------------------------------------------------------
 .../multipart/JakartaStreamMultiPartRequest.java          | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/b84fd6fe/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java
b/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java
index 6727f3e..f4c4665 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequest.java
@@ -384,6 +384,12 @@ public class JakartaStreamMultiPartRequest implements MultiPartRequest
{
      * @param location location
      */
     private void processFileItemStreamAsFileField(FileItemStream itemStream, String location)
{
+        // Skip file uploads that don't have a file name - meaning that no file was selected.
+        if (itemStream.getName() == null || itemStream.getName().trim().length() < 1)
{
+            LOG.debug("No file has been uploaded for the field: {}", itemStream.getFieldName());
+            return;
+        }
+
         File file = null;
         try {
             // Create the temporary upload file.
@@ -424,6 +430,10 @@ public class JakartaStreamMultiPartRequest implements MultiPartRequest
{
             suffix = name.substring(name.lastIndexOf('.'));
         }
 
+        if (prefix.length() < 3) {
+            prefix = UUID.randomUUID().toString();
+        }
+
         File file = File.createTempFile(prefix + "_", suffix, new File(location));
         LOG.debug("Creating temporary file '{}' (originally '{}').", file.getName(), fileName);
         return file;


Mime
View raw message