[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/LOOLWSD.cpp loolwsd/Storage.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sun Apr 17 15:26:56 UTC 2016
loolwsd/DocumentBroker.cpp | 16 ++++++++++++----
loolwsd/LOOLWSD.cpp | 1 -
loolwsd/Storage.cpp | 11 ++++++-----
3 files changed, 18 insertions(+), 10 deletions(-)
New commits:
commit ea223f14d2eb883762d88ab02561674083cc9f2b
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Apr 17 11:05:39 2016 -0400
loolwsd: storage validation should throw BadRequest on failure
Change-Id: I8e9eca96e3e9cef7391a74d72db806e6d1085b01
Reviewed-on: https://gerrit.libreoffice.org/24161
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 85a8d17..7fdb7b3 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -12,8 +12,9 @@
#include <Poco/Path.h>
#include <Poco/SHA1Engine.h>
-#include "LOOLWSD.hpp"
#include "DocumentBroker.hpp"
+#include "Exceptions.hpp"
+#include "LOOLWSD.hpp"
#include "Storage.hpp"
#include "TileCache.hpp"
@@ -81,10 +82,17 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
void DocumentBroker::validate(const Poco::URI& uri)
{
Log::info("Validating: " + uri.toString());
- auto storage = StorageBase::create("", "", uri);
- if (storage == nullptr || !storage->getFileInfo(uri).isValid())
+ try
+ {
+ auto storage = StorageBase::create("", "", uri);
+ if (storage == nullptr || !storage->getFileInfo(uri).isValid())
+ {
+ throw BadRequestException("Invalid URI or access denied.");
+ }
+ }
+ catch (const std::exception&)
{
- throw std::runtime_error("Invalid URI or access denied.");
+ throw BadRequestException("Invalid URI or access denied.");
}
}
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index c608925..9c62d0c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -705,7 +705,6 @@ public:
{
Log::error(std::string("ClientRequestHandler::handleRequest: BadRequestException: ") + exc.what());
response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
-
}
catch (const std::exception& exc)
{
diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp
index 67ed5ec..2e227b5 100644
--- a/loolwsd/Storage.cpp
+++ b/loolwsd/Storage.cpp
@@ -137,11 +137,12 @@ std::unique_ptr<StorageBase> StorageBase::create(const std::string& jailRoot, co
/////////////////////
StorageBase::FileInfo LocalStorage::getFileInfo(const Poco::URI& uri)
{
- const auto& path = uri.getPath();
- Log::debug("Getting info for local uri [" + uri.toString() + "], path [" + path + "].");
- const auto filename = Poco::Path(path).getFileName();
- const auto lastModified = Poco::File(path).getLastModified();
- const auto size = Poco::File(path).getSize();
+ const auto path = Poco::Path(uri.getPath());
+ Log::debug("Getting info for local uri [" + uri.toString() + "], path [" + path.toString() + "].");
+ const auto filename = path.getFileName();
+ const auto file = Poco::File(path);
+ const auto lastModified = file.getLastModified();
+ const auto size = file.getSize();
return FileInfo({filename, lastModified, size});
}
More information about the Libreoffice-commits
mailing list