From 685b0df2b517bee5d2b92e5b9b04823df75676c6 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 2 Sep 2020 20:29:04 -0700 Subject: [PATCH] fix: avoid creating client_id file for empty DIR_CRASH_DUMPS --- .../api/electron_api_crash_reporter.cc | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/shell/browser/api/electron_api_crash_reporter.cc b/shell/browser/api/electron_api_crash_reporter.cc index 4408d1f92ff3a..0c61995576a9e 100644 --- a/shell/browser/api/electron_api_crash_reporter.cc +++ b/shell/browser/api/electron_api_crash_reporter.cc @@ -86,18 +86,22 @@ const std::map& GetGlobalCrashKeys() { return GetGlobalCrashKeysMutable(); } -base::FilePath GetClientIdPath() { - base::FilePath path; - base::PathService::Get(electron::DIR_CRASH_DUMPS, &path); - return path.Append("client_id"); +bool GetClientIdPath(base::FilePath* path) { + if (base::PathService::Get(electron::DIR_CRASH_DUMPS, path)) { + *path = path->Append("client_id"); + return true; + } + return false; } std::string ReadClientId() { base::ThreadRestrictions::ScopedAllowIO allow_io; std::string client_id; // "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".length == 36 - if (!base::ReadFileToStringWithMaxSize(GetClientIdPath(), &client_id, 36) || - client_id.size() != 36) + base::FilePath client_id_path; + if (GetClientIdPath(&client_id_path) && + (!base::ReadFileToStringWithMaxSize(client_id_path, &client_id, 36) || + client_id.size() != 36)) return std::string(); return client_id; } @@ -105,7 +109,9 @@ std::string ReadClientId() { void WriteClientId(const std::string& client_id) { DCHECK_EQ(client_id.size(), 36u); base::ThreadRestrictions::ScopedAllowIO allow_io; - base::WriteFile(GetClientIdPath(), client_id); + base::FilePath client_id_path; + if (GetClientIdPath(&client_id_path)) + base::WriteFile(client_id_path, client_id); } std::string GetClientId() {