Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1403)

Unified Diff: chrome/browser/extensions/external_registry_extension_loader_win.cc

Issue 7650014: Check that registry external extension records point to a readable CRX file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: r Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/external_registry_extension_loader_win.cc
diff --git a/chrome/browser/extensions/external_registry_extension_loader_win.cc b/chrome/browser/extensions/external_registry_extension_loader_win.cc
index 55ab9ad3ea53db3f3257f4e4fffb4db64307c231..b57d79c4a673f6dc92deff6b4e762ae8b99b3859 100644
--- a/chrome/browser/extensions/external_registry_extension_loader_win.cc
+++ b/chrome/browser/extensions/external_registry_extension_loader_win.cc
@@ -5,6 +5,8 @@
#include "chrome/browser/extensions/external_registry_extension_loader_win.h"
#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/memory/scoped_handle.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -27,6 +29,11 @@ const wchar_t kRegistryExtensionPath[] = L"path";
// Registry value of that key that defines the current version of the .crx file.
const wchar_t kRegistryExtensionVersion[] = L"version";
+bool CanOpenFileForReading(const FilePath& path) {
+ ScopedStdioHandle file_handle(file_util::OpenFile(path, "rb"));
+ return file_handle.get() != NULL;
+}
+
} // namespace
void ExternalRegistryExtensionLoader::StartLoading() {
@@ -44,64 +51,80 @@ void ExternalRegistryExtensionLoader::LoadOnFileThread() {
base::win::RegistryKeyIterator iterator(
kRegRoot, ASCIIToWide(kRegistryExtensions).c_str());
- while (iterator.Valid()) {
+ for (; iterator.Valid(); ++iterator) {
base::win::RegKey key;
std::wstring key_path = ASCIIToWide(kRegistryExtensions);
key_path.append(L"\\");
key_path.append(iterator.Name());
- if (key.Open(kRegRoot, key_path.c_str(), KEY_READ) == ERROR_SUCCESS) {
- std::wstring extension_path_str;
- if (key.ReadValue(kRegistryExtensionPath, &extension_path_str)
- == ERROR_SUCCESS) {
- FilePath extension_path(extension_path_str);
- if (!extension_path.IsAbsolute()) {
- LOG(ERROR) << "Path " << extension_path_str
- << " needs to be absolute in key "
- << key_path;
- ++iterator;
- continue;
- }
- std::wstring extension_version;
- if (key.ReadValue(kRegistryExtensionVersion, &extension_version)
- == ERROR_SUCCESS) {
- std::string id = WideToASCII(iterator.Name());
- StringToLowerASCII(&id);
-
- if (!Extension::IdIsValid(id)) {
- LOG(ERROR) << "Invalid id value " << id
- << " for key " << key_path << " .";
- ++iterator;
- continue;
- }
-
- scoped_ptr<Version> version;
- version.reset(Version::GetVersionFromString(
- WideToASCII(extension_version)));
- if (!version.get()) {
- LOG(ERROR) << "Invalid version value " << extension_version
- << " for key " << key_path << " .";
- ++iterator;
- continue;
- }
-
- prefs->SetString(
- id + "." + ExternalExtensionProviderImpl::kExternalVersion,
- WideToASCII(extension_version));
- prefs->SetString(
- id + "." + ExternalExtensionProviderImpl::kExternalCrx,
- extension_path_str);
- } else {
- // TODO(erikkay): find a way to get this into about:extensions
- LOG(ERROR) << "Missing value " << kRegistryExtensionVersion
- << " for key " << key_path << " .";
- }
- } else {
- // TODO(erikkay): find a way to get this into about:extensions
- LOG(ERROR) << "Missing value " << kRegistryExtensionPath
- << " for key " << key_path << " .";
- }
+ if (key.Open(kRegRoot, key_path.c_str(), KEY_READ) != ERROR_SUCCESS) {
+ LOG(ERROR) << "Unable to read key at path: " << key_path << " .";
+ continue;
}
- ++iterator;
+
+ std::wstring extension_path_str;
+ if (key.ReadValue(kRegistryExtensionPath, &extension_path_str)
+ != ERROR_SUCCESS) {
+ // TODO(erikkay): find a way to get this into about:extensions
+ LOG(ERROR) << "Missing value " << kRegistryExtensionPath
+ << " for key " << key_path << " .";
+ continue;
+ }
+
+ FilePath extension_path(extension_path_str);
+ if (!extension_path.IsAbsolute()) {
+ LOG(ERROR) << "Path " << extension_path_str
+ << " needs to be absolute in key "
+ << key_path;
+ continue;
+ }
+
+ if (!file_util::PathExists(extension_path)) {
+ LOG(ERROR) << "Path " << extension_path_str
+ << " for key " << key_path
+ << " does not exist or is not readable.";
+ continue;
+ }
+
+ if (!CanOpenFileForReading(extension_path)) {
+ LOG(ERROR) << "Path " << extension_path_str
Finnur 2011/08/16 10:39:33 nit: Path -> File
Sam Kerner (Chrome) 2011/08/16 18:25:52 Done.
+ << " for key " << key_path << " can not be read. "
Finnur 2011/08/16 10:39:33 nit: One space before second closing double quote.
Sam Kerner (Chrome) 2011/08/16 18:25:52 Done.
+ << "Check that users who should have the extension "
+ << "installed have permission to read it.";
+ continue;
+ }
+
+ std::wstring extension_version;
+ if (key.ReadValue(kRegistryExtensionVersion, &extension_version)
+ != ERROR_SUCCESS) {
+ // TODO(erikkay): find a way to get this into about:extensions
+ LOG(ERROR) << "Missing value " << kRegistryExtensionVersion
+ << " for key " << key_path << " .";
Finnur 2011/08/16 10:39:33 nit: Why space before period? (same below, two occ
Sam Kerner (Chrome) 2011/08/16 18:25:52 I was following existing practice, but I agree it
Finnur 2011/08/17 10:46:25 What do you mean existing practice? I've never not
Sam Kerner (Chrome) 2011/08/17 14:42:44 There were a few places in this function that did
Finnur 2011/08/17 14:51:17 to this: <something> << "."; ... you mean? :)
+ continue;
+ }
+
+ std::string id = WideToASCII(iterator.Name());
+ StringToLowerASCII(&id);
+ if (!Extension::IdIsValid(id)) {
+ LOG(ERROR) << "Invalid id value " << id
+ << " for key " << key_path << " .";
+ continue;
+ }
+
+ scoped_ptr<Version> version;
+ version.reset(Version::GetVersionFromString(
+ WideToASCII(extension_version)));
+ if (!version.get()) {
+ LOG(ERROR) << "Invalid version value " << extension_version
+ << " for key " << key_path << " .";
+ continue;
+ }
+
+ prefs->SetString(
+ id + "." + ExternalExtensionProviderImpl::kExternalVersion,
+ WideToASCII(extension_version));
+ prefs->SetString(
+ id + "." + ExternalExtensionProviderImpl::kExternalCrx,
+ extension_path_str);
}
prefs_.reset(prefs.release());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698