From a4b9945226bd4fea9c5b9d11a44a3d2d24f65cc8 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 21 Sep 2017 16:17:54 -0700 Subject: [PATCH] Fix use after free in deleteMappings --- assignment-client/src/assets/AssetServer.cpp | 11 +++++------ assignment-client/src/assets/AssetServer.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 1f86b65029..9df606c227 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -953,16 +953,15 @@ void AssetServer::removeBakedPathsForDeletedAsset(AssetHash hash) { deleteMappings(hiddenBakedFolder); } -bool AssetServer::deleteMappings(AssetPathList& paths) { +bool AssetServer::deleteMappings(const AssetPathList& paths) { // take a copy of the current mappings in case persistence of these deletes fails auto oldMappings = _fileMappings; QSet hashesToCheckForDeletion; // enumerate the paths to delete and remove them all - for (auto& path : paths) { - - path = path.trimmed(); + for (const auto& rawPath : paths) { + auto path = rawPath.trimmed(); // figure out if this path will delete a file or folder if (pathIsFolder(path)) { @@ -991,12 +990,12 @@ bool AssetServer::deleteMappings(AssetPathList& paths) { } else { auto it = _fileMappings.find(path); if (it != _fileMappings.end()) { - _fileMappings.erase(it); - // add this hash to the list we need to check for asset removal from server hashesToCheckForDeletion << it->second; qCDebug(asset_server) << "Deleted a mapping:" << path << "=>" << it->second; + + _fileMappings.erase(it); } else { qCDebug(asset_server) << "Unable to delete a mapping that was not found:" << path; } diff --git a/assignment-client/src/assets/AssetServer.h b/assignment-client/src/assets/AssetServer.h index 1589dde3e3..94be560c9b 100644 --- a/assignment-client/src/assets/AssetServer.h +++ b/assignment-client/src/assets/AssetServer.h @@ -78,7 +78,7 @@ private: bool setMapping(AssetPath path, AssetHash hash); /// Delete mapping `path`. Returns `true` if deletion of mappings succeeds, else `false`. - bool deleteMappings(AssetPathList& paths); + bool deleteMappings(const AssetPathList& paths); /// Rename mapping from `oldPath` to `newPath`. Returns true if successful bool renameMapping(AssetPath oldPath, AssetPath newPath);