From 7670d72bd9c8bb2adcecd2d04413a2abb9ac174f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 26 Dec 2015 03:20:41 +0100 Subject: GH-1178 sanitize mod paths while installing folder mods --- logic/minecraft/ModList.cpp | 19 ++++++++++++------- logic/minecraft/ModList.h | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'logic') diff --git a/logic/minecraft/ModList.cpp b/logic/minecraft/ModList.cpp index a1640d2e..d9ed4886 100644 --- a/logic/minecraft/ModList.cpp +++ b/logic/minecraft/ModList.cpp @@ -235,13 +235,18 @@ bool ModList::isValid() return m_dir.exists() && m_dir.isReadable(); } -bool ModList::installMod(const QFileInfo &filename, int index) +bool ModList::installMod(const QString &filename, int index) { - if (!filename.exists() || !filename.isReadable() || index < 0) + // NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName + QFileInfo fileinfo(FS::NormalizePath(filename)); + + qDebug() << "installing: " << fileinfo.absoluteFilePath(); + + if (!fileinfo.exists() || !fileinfo.isReadable() || index < 0) { return false; } - Mod m(filename); + Mod m(fileinfo); if (!m.valid()) return false; @@ -270,8 +275,8 @@ bool ModList::installMod(const QFileInfo &filename, int index) return false; if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD) { - QString newpath = FS::PathCombine(m_dir.path(), filename.fileName()); - if (!QFile::copy(filename.filePath(), newpath)) + QString newpath = FS::PathCombine(m_dir.path(), fileinfo.fileName()); + if (!QFile::copy(fileinfo.filePath(), newpath)) return false; m.repath(newpath); beginInsertRows(QModelIndex(), index, index); @@ -284,8 +289,8 @@ bool ModList::installMod(const QFileInfo &filename, int index) else if (type == Mod::MOD_FOLDER) { - QString from = filename.filePath(); - QString to = FS::PathCombine(m_dir.path(), filename.fileName()); + QString from = fileinfo.filePath(); + QString to = FS::PathCombine(m_dir.path(), fileinfo.fileName()); if (!FS::copy(from, to)()) return false; m.repath(to); diff --git a/logic/minecraft/ModList.h b/logic/minecraft/ModList.h index 823854ed..05ada8ee 100644 --- a/logic/minecraft/ModList.h +++ b/logic/minecraft/ModList.h @@ -77,7 +77,7 @@ public: /** * Adds the given mod to the list at the given index - if the list supports custom ordering */ - virtual bool installMod(const QFileInfo &filename, int index = 0); + virtual bool installMod(const QString & filename, int index = 0); /// Deletes the mod at the given index. virtual bool deleteMod(int index); -- cgit v1.2.3