From 97bb43d7e9705078dc92c0187c105bd1ba6ad6c8 Mon Sep 17 00:00:00 2001 From: Rafal Walczyna Date: Wed, 23 May 2018 12:39:08 +0200 Subject: [PATCH] [Filesystem] Resolving unexpected result of coverity issues Time of checking to time of use is already short as possible. [verification] Build successful Change-Id: Ifa55b413962fb88321771ac952487f6901581790 Signed-off-by: Rafal Walczyna --- src/filesystem/filesystem_manager.cc | 3 +-- src/filesystem/filesystem_manager.h | 2 +- src/filesystem/filesystem_stat.cc | 3 +-- src/filesystem/filesystem_stat.h | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/filesystem/filesystem_manager.cc b/src/filesystem/filesystem_manager.cc index a95f5b17..8ca885d3 100644 --- a/src/filesystem/filesystem_manager.cc +++ b/src/filesystem/filesystem_manager.cc @@ -289,8 +289,7 @@ void FilesystemManager::MakeDirectory(const std::string& path, result_cb(make_directory_worker(path)); } -// pass oldPath by copy to prevent possible TOCTOU bug -void FilesystemManager::Rename(const std::string oldPath, const std::string& newPath, +void FilesystemManager::Rename(const std::string& oldPath, const std::string& newPath, const std::function& success_cb, const std::function& error_cb) { ScopeLogger(); diff --git a/src/filesystem/filesystem_manager.h b/src/filesystem/filesystem_manager.h index eaadf9ba..e0d2d12b 100644 --- a/src/filesystem/filesystem_manager.h +++ b/src/filesystem/filesystem_manager.h @@ -69,7 +69,7 @@ class FilesystemManager { const std::function& success_cb, const std::function& error_cb); - void Rename(const std::string oldPath, const std::string& newPath, + void Rename(const std::string& oldPath, const std::string& newPath, const std::function& success_cb, const std::function& error_cb); diff --git a/src/filesystem/filesystem_stat.cc b/src/filesystem/filesystem_stat.cc index bb5bc89b..feb7bed6 100644 --- a/src/filesystem/filesystem_stat.cc +++ b/src/filesystem/filesystem_stat.cc @@ -59,8 +59,7 @@ picojson::value FilesystemStat::toJSON() const { return retval; } -// pass path by copy to prevent possible TOCTOU bug -FilesystemStat FilesystemStat::getStat(const std::string path) { +FilesystemStat FilesystemStat::getStat(const std::string& path) { ScopeLogger(); struct stat aStatObj; FilesystemStat _result; diff --git a/src/filesystem/filesystem_stat.h b/src/filesystem/filesystem_stat.h index 31c58875..a984ab1d 100755 --- a/src/filesystem/filesystem_stat.h +++ b/src/filesystem/filesystem_stat.h @@ -49,7 +49,7 @@ class FilesystemStat { picojson::value toJSON() const; - static FilesystemStat getStat(const std::string path); + static FilesystemStat getStat(const std::string& path); }; } // namespace filesystem } // namespace extension -- 2.34.1