aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-03-23 20:43:02 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-03-23 21:49:22 +0900
commit9ba481f2c8e7f1db6144ece7119d8cc314c57bc5 (patch)
tree960d6605a770019b6bc4d918ef965141d91dac69 /lib
parent01d9f7b3f1785034503497798fb732ee6ee5fba3 (diff)
downloadlibquotient-9ba481f2c8e7f1db6144ece7119d8cc314c57bc5.tar.gz
libquotient-9ba481f2c8e7f1db6144ece7119d8cc314c57bc5.zip
Room::downloadFile(): Tighten URL validations
Check the URL before passing over to Connection::downloadFile(), not only the file name.
Diffstat (limited to 'lib')
-rw-r--r--lib/events/eventcontent.cpp6
-rw-r--r--lib/events/eventcontent.h2
-rw-r--r--lib/room.cpp9
3 files changed, 16 insertions, 1 deletions
diff --git a/lib/events/eventcontent.cpp b/lib/events/eventcontent.cpp
index 9a5e872c..77f756cd 100644
--- a/lib/events/eventcontent.cpp
+++ b/lib/events/eventcontent.cpp
@@ -50,6 +50,12 @@ FileInfo::FileInfo(const QUrl& u, const QJsonObject& infoJson,
mimeType = QMimeDatabase().mimeTypeForData(QByteArray());
}
+bool FileInfo::isValid() const
+{
+ return url.scheme() == "mxc"
+ && (url.authority() + url.path()).count('/') == 1;
+}
+
void FileInfo::fillInfoJson(QJsonObject* infoJson) const
{
Q_ASSERT(infoJson);
diff --git a/lib/events/eventcontent.h b/lib/events/eventcontent.h
index 0588c0e2..ab31a75d 100644
--- a/lib/events/eventcontent.h
+++ b/lib/events/eventcontent.h
@@ -94,6 +94,8 @@ namespace QMatrixClient
FileInfo(const QUrl& u, const QJsonObject& infoJson,
const QString& originalFilename = {});
+ bool isValid() const;
+
void fillInfoJson(QJsonObject* infoJson) const;
/**
diff --git a/lib/room.cpp b/lib/room.cpp
index 7494917d..ce7bae04 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1785,7 +1785,14 @@ void Room::downloadFile(const QString& eventId, const QUrl& localFilename)
Q_ASSERT(false);
return;
}
- const auto fileUrl = event->content()->fileInfo()->url;
+ const auto* const fileInfo = event->content()->fileInfo();
+ if (!fileInfo->isValid())
+ {
+ qCWarning(MAIN) << "Event" << eventId
+ << "has an empty or malformed mxc URL; won't download";
+ return;
+ }
+ const auto fileUrl = fileInfo->url;
auto filePath = localFilename.toLocalFile();
if (filePath.isEmpty())
{