diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-20 04:19:05 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-20 04:19:05 +0000 |
commit | f0737f2b1a9fad2a04f1c09d2403fdc78b659a3a (patch) | |
tree | a06fca3830dfa35444da5ed94d0d42fb4bc0d2ed | |
parent | ab8d887759ba48ce856885f11ffb6afe837ca933 (diff) | |
download | chromium_src-f0737f2b1a9fad2a04f1c09d2403fdc78b659a3a.zip chromium_src-f0737f2b1a9fad2a04f1c09d2403fdc78b659a3a.tar.gz chromium_src-f0737f2b1a9fad2a04f1c09d2403fdc78b659a3a.tar.bz2 |
Fix incorrect file_util::WriteFile() checks.
Review URL: https://chromiumcodereview.appspot.com/23775008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224281 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/external_metrics.cc | 11 | ||||
-rw-r--r-- | chrome/browser/policy/cloud/resource_cache.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/network_profile_bubble.cc | 2 | ||||
-rw-r--r-- | chrome/installer/setup/install.cc | 6 |
4 files changed, 13 insertions, 10 deletions
diff --git a/chrome/browser/chromeos/external_metrics.cc b/chrome/browser/chromeos/external_metrics.cc index 98b62c4..b0ae298 100644 --- a/chrome/browser/chromeos/external_metrics.cc +++ b/chrome/browser/chromeos/external_metrics.cc @@ -61,7 +61,8 @@ bool CheckLinearValues(const std::string& name, int maximum) { void SetupProgressiveScanFieldTrial() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); const char name_of_experiment[] = "ProgressiveScan"; - const char path_to_group_file[] = "/home/chronos/.progressive_scan_variation"; + const base::FilePath group_file_path( + "/home/chronos/.progressive_scan_variation"); const base::FieldTrial::Probability kDivisor = 1000; scoped_refptr<base::FieldTrial> trial = base::FieldTrialList::FactoryGetFieldTrial( @@ -85,15 +86,13 @@ void SetupProgressiveScanFieldTrial() { group_char = group_to_char[group_num]; // Write the group to the file to be read by ChromeOS. - const base::FilePath kPathToGroupFile(path_to_group_file); - - if (file_util::WriteFile(kPathToGroupFile, group_char.c_str(), - group_char.length())) { + int size = static_cast<int>(group_char.length()); + if (file_util::WriteFile(group_file_path, group_char.c_str(), size) == size) { LOG(INFO) << "Configured in group '" << trial->group_name() << "' ('" << group_char << "') for " << name_of_experiment << " field trial"; } else { - LOG(ERROR) << "Couldn't write to " << path_to_group_file; + LOG(ERROR) << "Couldn't write to " << group_file_path.value(); } } diff --git a/chrome/browser/policy/cloud/resource_cache.cc b/chrome/browser/policy/cloud/resource_cache.cc index b71ff46..6d8bd24 100644 --- a/chrome/browser/policy/cloud/resource_cache.cc +++ b/chrome/browser/policy/cloud/resource_cache.cc @@ -8,6 +8,7 @@ #include "base/file_util.h" #include "base/files/file_enumerator.h" #include "base/logging.h" +#include "base/safe_numerics.h" #include "base/sequenced_task_runner.h" #include "base/strings/string_util.h" @@ -79,9 +80,10 @@ bool ResourceCache::Store(const std::string& key, // between these two calls. There is nothing in file_util that could be used // to protect against such races, especially as the cache is cross-platform // and therefore cannot use any POSIX-only tricks. + int size = base::checked_numeric_cast<int>(data.size()); return VerifyKeyPathAndGetSubkeyPath(key, true, subkey, &subkey_path) && base::DeleteFile(subkey_path, false) && - file_util::WriteFile(subkey_path, data.data(), data.size()); + (file_util::WriteFile(subkey_path, data.data(), size) == size); } bool ResourceCache::Load(const std::string& key, diff --git a/chrome/browser/ui/network_profile_bubble.cc b/chrome/browser/ui/network_profile_bubble.cc index c2169b1..6de46c3 100644 --- a/chrome/browser/ui/network_profile_bubble.cc +++ b/chrome/browser/ui/network_profile_bubble.cc @@ -128,7 +128,7 @@ void NetworkProfileBubble::CheckNetworkProfile( // Try to create some non-empty temp file in the profile dir and use // it to check if there is a reparse-point free path to it. if (file_util::CreateTemporaryFileInDir(profile_folder, &temp_file) && - file_util::WriteFile(temp_file, ".", 1)) { + (file_util::WriteFile(temp_file, ".", 1) == 1)) { base::FilePath normalized_temp_file; if (!file_util::NormalizeFilePath(temp_file, &normalized_temp_file)) profile_on_network = true; diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index 688df1c..d8d6b84 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -17,6 +17,7 @@ #include "base/memory/scoped_ptr.h" #include "base/path_service.h" #include "base/process/launch.h" +#include "base/safe_numerics.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -340,9 +341,10 @@ bool CreateVisualElementsManifest(const base::FilePath& src_path, // Write the manifest to |src_path|. const std::string manifest(UTF16ToUTF8(manifest16)); + int size = base::checked_numeric_cast<int>(manifest.size()); if (file_util::WriteFile( - src_path.Append(installer::kVisualElementsManifest), - manifest.c_str(), manifest.size())) { + src_path.Append(installer::kVisualElementsManifest), + manifest.c_str(), size) == size) { VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest << " to " << src_path.value(); return true; |