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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri Jul 29 12:44:01 UTC 2016


 loolwsd/FileServer.cpp |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

New commits:
commit a5716da8f88a1ae79a227e2649d95b83e77f7cdd
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri Jul 29 08:42:43 2016 -0400

    loolwsd: fail gracefully on invalid file requests
    
    Change-Id: I576623de1251c916f3a54dca8e470d8989710e40
    Reviewed-on: https://gerrit.libreoffice.org/27687
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/FileServer.cpp b/loolwsd/FileServer.cpp
index eef1b48..a18ee17 100644
--- a/loolwsd/FileServer.cpp
+++ b/loolwsd/FileServer.cpp
@@ -211,9 +211,17 @@ void FileServerRequestHandler::preprocessFile(HTTPServerRequest& request, HTTPSe
 
     const auto host = (LOOLWSD::isSSLEnabled() ? "wss://" : "ws://") + (LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName);
     const auto path = Poco::Path(LOOLWSD::FileServerRoot, getRequestPathname(request));
-
     Log::debug("Preprocessing file: " + path.toString());
 
+    if (!Poco::File(path).exists())
+    {
+        Log::error("File [" + path.toString() + "] does not exist.");
+        response.setStatusAndReason(HTTPResponse::HTTP_NOT_FOUND);
+        response.setContentLength(0); // TODO return some 404 page?
+        response.send();
+        return;
+    }
+
     std::string preprocess;
     FileInputStream file(path.toString());
     StreamCopier::copyToString(file, preprocess);


More information about the Libreoffice-commits mailing list