summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-17 22:43:31 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-17 22:43:31 +0000
commitfc006cac2085cf5bcc3be856cbf9085fba11aa4b (patch)
treedd03da9ff585773d2dd0558cbbff11da563a73e4
parentd4d844a29b271cabb96ca6d5bdccce8056c1b16f (diff)
downloadchromium_src-fc006cac2085cf5bcc3be856cbf9085fba11aa4b.zip
chromium_src-fc006cac2085cf5bcc3be856cbf9085fba11aa4b.tar.gz
chromium_src-fc006cac2085cf5bcc3be856cbf9085fba11aa4b.tar.bz2
Fix incorrect checking of file_util::WriteFile() return results.
Review URL: https://chromiumcodereview.appspot.com/23865006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223723 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/convert_web_app.cc4
-rw-r--r--chrome/browser/extensions/sandboxed_unpacker.cc16
-rw-r--r--chrome/browser/net/crl_set_fetcher.cc9
-rw-r--r--chrome/utility/extensions/unpacker.cc14
-rw-r--r--cloud_print/gcp20/prototype/printer_state.cc5
-rw-r--r--content/browser/tracing/tracing_ui.cc6
6 files changed, 34 insertions, 20 deletions
diff --git a/chrome/browser/extensions/convert_web_app.cc b/chrome/browser/extensions/convert_web_app.cc
index 39c905b..85326e3 100644
--- a/chrome/browser/extensions/convert_web_app.cc
+++ b/chrome/browser/extensions/convert_web_app.cc
@@ -16,6 +16,7 @@
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
#include "base/path_service.h"
+#include "base/safe_numerics.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
@@ -172,7 +173,8 @@ scoped_refptr<Extension> ConvertWebAppToExtension(
}
const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]);
- if (!file_util::WriteFile(icon_file, image_data_ptr, image_data.size())) {
+ int size = base::checked_numeric_cast<int>(image_data.size());
+ if (file_util::WriteFile(icon_file, image_data_ptr, size) != size) {
LOG(ERROR) << "Could not write icon file.";
return NULL;
}
diff --git a/chrome/browser/extensions/sandboxed_unpacker.cc b/chrome/browser/extensions/sandboxed_unpacker.cc
index 6a9d6e1..6832bfd 100644
--- a/chrome/browser/extensions/sandboxed_unpacker.cc
+++ b/chrome/browser/extensions/sandboxed_unpacker.cc
@@ -16,6 +16,7 @@
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
+#include "base/safe_numerics.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -130,7 +131,8 @@ bool VerifyJunctionFreeLocation(base::FilePath* temp_dir) {
// NormalizeFilePath requires a non-empty file, so write some data.
// If you change the exit points of this function please make sure all
// exit points delete this temp file!
- file_util::WriteFile(temp_file, ".", 1);
+ if (file_util::WriteFile(temp_file, ".", 1) != 1)
+ return false;
base::FilePath normalized_temp_file;
bool normalized =
@@ -623,8 +625,8 @@ DictionaryValue* SandboxedUnpacker::RewriteManifestFile(
base::FilePath manifest_path =
extension_root_.Append(kManifestFilename);
- if (!file_util::WriteFile(manifest_path,
- manifest_json.data(), manifest_json.size())) {
+ int size = base::checked_numeric_cast<int>(manifest_json.size());
+ if (file_util::WriteFile(manifest_path, manifest_json.data(), size) != size) {
// Error saving manifest.json.
ReportFailure(
ERROR_SAVING_MANIFEST_JSON,
@@ -736,7 +738,8 @@ bool SandboxedUnpacker::RewriteImageFiles(SkBitmap* install_icon) {
// Note: we're overwriting existing files that the utility process wrote,
// so we can be sure the directory exists.
const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]);
- if (!file_util::WriteFile(path, image_data_ptr, image_data.size())) {
+ int size = base::checked_numeric_cast<int>(image_data.size());
+ if (file_util::WriteFile(path, image_data_ptr, size) != size) {
// Error saving theme image.
ReportFailure(
ERROR_SAVING_THEME_IMAGE,
@@ -803,9 +806,8 @@ bool SandboxedUnpacker::RewriteCatalogFiles() {
// Note: we're overwriting existing files that the utility process read,
// so we can be sure the directory exists.
- if (!file_util::WriteFile(path,
- catalog_json.c_str(),
- catalog_json.size())) {
+ int size = base::checked_numeric_cast<int>(catalog_json.size());
+ if (file_util::WriteFile(path, catalog_json.c_str(), size) != size) {
// Error saving catalog.
ReportFailure(
ERROR_SAVING_CATALOG,
diff --git a/chrome/browser/net/crl_set_fetcher.cc b/chrome/browser/net/crl_set_fetcher.cc
index 464d0d1..306db47 100644
--- a/chrome/browser/net/crl_set_fetcher.cc
+++ b/chrome/browser/net/crl_set_fetcher.cc
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/rand_util.h"
+#include "base/safe_numerics.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/component_updater/component_updater_service.h"
@@ -169,8 +170,8 @@ bool CRLSetFetcher::Install(const base::DictionaryValue& manifest,
LOG(WARNING) << "Failed to parse CRL set from update CRX";
return false;
}
- if (!file_util::WriteFile(save_to, crl_set_bytes.data(),
- crl_set_bytes.size())) {
+ int size = base::checked_numeric_cast<int>(crl_set_bytes.size());
+ if (file_util::WriteFile(save_to, crl_set_bytes.data(), size) != size) {
LOG(WARNING) << "Failed to save new CRL set to disk";
// We don't return false here because we can still use this CRL set. When
// we restart we might revert to an older version, then we'll
@@ -185,8 +186,8 @@ bool CRLSetFetcher::Install(const base::DictionaryValue& manifest,
VLOG(1) << "Applied CRL set delta #" << crl_set_->sequence()
<< "->#" << new_crl_set->sequence();
const std::string new_crl_set_bytes = new_crl_set->Serialize();
- if (!file_util::WriteFile(save_to, new_crl_set_bytes.data(),
- new_crl_set_bytes.size())) {
+ int size = base::checked_numeric_cast<int>(new_crl_set_bytes.size());
+ if (file_util::WriteFile(save_to, new_crl_set_bytes.data(), size) != size) {
LOG(WARNING) << "Failed to save new CRL set to disk";
// We don't return false here because we can still use this CRL set. When
// we restart we might revert to an older version, then we'll
diff --git a/chrome/utility/extensions/unpacker.cc b/chrome/utility/extensions/unpacker.cc
index f2c6727..caeaf6e 100644
--- a/chrome/utility/extensions/unpacker.cc
+++ b/chrome/utility/extensions/unpacker.cc
@@ -12,6 +12,7 @@
#include "base/i18n/rtl.h"
#include "base/json/json_file_value_serializer.h"
#include "base/memory/scoped_handle.h"
+#include "base/safe_numerics.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
@@ -85,6 +86,13 @@ bool PathContainsParentDirectory(const base::FilePath& path) {
return false;
}
+bool WritePickle(const IPC::Message& pickle, const base::FilePath& dest_path) {
+ int size = base::checked_numeric_cast<int>(pickle.size());
+ const char* data = static_cast<const char*>(pickle.data());
+ int bytes_written = file_util::WriteFile(dest_path, data, size);
+ return (bytes_written == size);
+}
+
} // namespace
struct Unpacker::InternalData {
@@ -228,8 +236,7 @@ bool Unpacker::DumpImagesToFile() {
base::FilePath path = extension_path_.DirName().AppendASCII(
kDecodedImagesFilename);
- if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()),
- pickle.size())) {
+ if (!WritePickle(pickle, path)) {
SetError("Could not write image data to disk.");
return false;
}
@@ -243,8 +250,7 @@ bool Unpacker::DumpMessageCatalogsToFile() {
base::FilePath path = extension_path_.DirName().AppendASCII(
kDecodedMessageCatalogsFilename);
- if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()),
- pickle.size())) {
+ if (!WritePickle(pickle, path)) {
SetError("Could not write message catalogs to disk.");
return false;
}
diff --git a/cloud_print/gcp20/prototype/printer_state.cc b/cloud_print/gcp20/prototype/printer_state.cc
index cf1891d..0c1ab09 100644
--- a/cloud_print/gcp20/prototype/printer_state.cc
+++ b/cloud_print/gcp20/prototype/printer_state.cc
@@ -8,6 +8,7 @@
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
+#include "base/safe_numerics.h"
#include "base/values.h"
namespace {
@@ -69,8 +70,8 @@ bool SaveToFile(const base::FilePath& path, const PrinterState& state) {
base::JSONWriter::WriteWithOptions(&json,
base::JSONWriter::OPTIONS_PRETTY_PRINT,
&json_str);
- return !!file_util::WriteFile(path, json_str.data(),
- static_cast<int>(json_str.size()));
+ int size = base::checked_numeric_cast<int>(json_str.size());
+ return (file_util::WriteFile(path, json_str.data(), size) == size);
}
bool LoadFromFile(const base::FilePath& path, PrinterState* state) {
diff --git a/content/browser/tracing/tracing_ui.cc b/content/browser/tracing/tracing_ui.cc
index 7793adb..15bd2cf 100644
--- a/content/browser/tracing/tracing_ui.cc
+++ b/content/browser/tracing/tracing_ui.cc
@@ -13,6 +13,7 @@
#include "base/file_util.h"
#include "base/json/string_escape.h"
#include "base/memory/scoped_ptr.h"
+#include "base/safe_numerics.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -269,7 +270,8 @@ void ReadTraceFileCallback(TaskProxy* proxy, const base::FilePath& path) {
void WriteTraceFileCallback(TaskProxy* proxy,
const base::FilePath& path,
std::string* contents) {
- if (!file_util::WriteFile(path, contents->c_str(), contents->size()))
+ int size = base::checked_numeric_cast<int>(contents->size());
+ if (file_util::WriteFile(path, contents->c_str(), size) != size)
return;
BrowserThread::PostTask(
@@ -363,7 +365,7 @@ void TracingMessageHandler::OnSaveTraceFile(const base::ListValue* list) {
if (select_trace_file_dialog_.get())
return;
- DCHECK(list->GetSize() == 1);
+ DCHECK_EQ(1U, list->GetSize());
std::string* trace_data = new std::string();
bool ok = list->GetString(0, trace_data);