diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-03 01:39:07 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-03 01:39:07 +0000 |
commit | c8ac83912c574059021eae381df36694159d8116 (patch) | |
tree | cc74a474ff537c3e00f38b0c9ce1e460e97b76f4 /chrome/browser/extensions | |
parent | 57f32a64e1f6cae6ccda9bbbdaa1672de3d0ea86 (diff) | |
download | chromium_src-c8ac83912c574059021eae381df36694159d8116.zip chromium_src-c8ac83912c574059021eae381df36694159d8116.tar.gz chromium_src-c8ac83912c574059021eae381df36694159d8116.tar.bz2 |
Coverity: Check the return value of file_util::ReadFileToString. It's possible that the file will be removed from the filesystem inbetween the enumeration and reading of the file. In this instance, the script is removed from the script list.
CID=3888
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/159680
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/user_script_master.cc | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index 39567d7..8c90a46 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -138,11 +138,17 @@ void UserScriptMaster::ScriptReloader::NotifyMaster( Release(); } -static void LoadScriptContent(UserScript::File* script_file) { +static bool LoadScriptContent(UserScript::File* script_file) { std::string content; - file_util::ReadFileToString(script_file->path(), &content); + if (!file_util::ReadFileToString(script_file->path(), &content)) { + LOG(WARNING) << "Failed to load user script file: " + << script_file->path().value(); + return false; + } + script_file->set_content(content); LOG(INFO) << "Loaded user script file: " << script_file->path().value(); + return true; } void UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory( @@ -168,8 +174,11 @@ void UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory( net::FilePathToFileURL(file).ExtractFileName()); user_script.js_scripts().push_back(UserScript::File(file, url)); UserScript::File& script_file = user_script.js_scripts().back(); - LoadScriptContent(&script_file); - ParseMetadataHeader(script_file.GetContent(), &user_script); + if (!LoadScriptContent(&script_file)) { + result->erase(result->end()); + } else { + ParseMetadataHeader(script_file.GetContent(), &user_script); + } } } } |