[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/Util.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue May 31 04:24:43 UTC 2016


 loolwsd/LOOLWSD.cpp |    7 ++++++-
 loolwsd/Util.cpp    |   19 +++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

New commits:
commit 886af28bc2f6d1d27bf78de09978f3858d2db705
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 30 21:43:18 2016 -0400

    loolwsd: improved random directory generator
    
    Change-Id: Ic4ea88ba77549cc4ccba83c27fffdffcdeebb984
    Reviewed-on: https://gerrit.libreoffice.org/25698
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index da2f72c..cd89457 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -420,7 +420,8 @@ private:
                     if (!resultURL.getPath().empty())
                     {
                         const std::string mimeType = "application/octet-stream";
-                        response.sendFile(resultURL.getPath(), mimeType);
+                        URI::encode(resultURL.getPath(), "", encodedTo);
+                        response.sendFile(encodedTo, mimeType);
                         sent = true;
                     }
 
@@ -504,6 +505,10 @@ private:
                 Util::removeFile(dirPath, true);
                 return true;
             }
+            else
+            {
+                Log::error("Download file [" + filePath + "] not found.");
+            }
         }
 
         throw BadRequestException("Invalid or unknown request.");
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 4e11d38..78a90f0 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -81,13 +81,27 @@ namespace rng
         return v;
     }
 
-    std::string getString(const size_t length)
+    /// Generates a random string in Base64.
+    /// Note: May contain '/' characters.
+    std::string getB64String(const size_t length)
     {
         std::stringstream ss;
         Poco::Base64Encoder b64(ss);
         b64 << getBytes(length).data();
         return ss.str().substr(0, length);
     }
+
+    /// Generates a random string suitable for
+    /// file/directory names.
+    std::string getFilename(const size_t length)
+    {
+        std::stringstream ss;
+        Poco::Base64Encoder b64(ss);
+        b64 << getBytes(length).data();
+        std::string s = ss.str();
+        std::replace(s.begin(), s.end(), '/', '_');
+        return s.substr(0, length);
+    }
 }
 }
 
@@ -109,10 +123,11 @@ namespace Util
         return id;
     }
 
+    /// Create a secure, random directory path.
     std::string createRandomDir(const std::string& path)
     {
         Poco::File(path).createDirectories();
-        const auto name = rng::getString(64);
+        const auto name = rng::getFilename(64);
         Poco::File(Poco::Path(path, name)).createDirectories();
         return name;
     }


More information about the Libreoffice-commits mailing list