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

Unified Diff: chrome/app/chrome_dll_main.cc

Issue 20469: Prevent chrome from launching with a chromehtml: argument... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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/app/chrome_dll_main.cc
===================================================================
--- chrome/app/chrome_dll_main.cc (revision 9872)
+++ chrome/app/chrome_dll_main.cc (working copy)
@@ -10,6 +10,7 @@
#include "build/build_config.h"
#if defined(OS_WIN)
+#include <algorithm>
#include <atlbase.h>
#include <atlapp.h>
#include <malloc.h>
@@ -116,6 +117,38 @@
#pragma optimize("", on)
+// Early versions of Chrome incorrectly registered a chromehtml: URL handler.
+// Later versions fixed the registration but in some cases (e.g. Vista and non-
+// admin installs) the fix could not be applied. This prevents Chrome to be
+// launched with the incorrect format.
+// CORRECT: <broser.exe> -- "chromehtml:<url>"
+// INVALID: <broser.exe> "chromehtml:<url>"
+bool IncorrectChromeHtmlArguments(const std::wstring& command_line) {
+ const wchar_t kChromeHtml[] = L"-- \"chromehtml:";
+ const wchar_t kOffset = 5; // Where chromehtml: starts in above
+ std::wstring command_line_lower = command_line;
+
+ // We are only searching for ASCII characters so this is OK.
+ StringToLowerASCII(&command_line_lower);
+
+ std::wstring::size_type pos = command_line_lower.find(
+ kChromeHtml + kOffset);
+
+ if (pos == std::wstring::npos)
+ return false;
+
+ // The browser is being launched with chromehtml: somewhere on the command
+ // line. We will not launch unless it's preceded by the -- switch terminator.
+ if (pos >= kOffset) {
+ if (equal(kChromeHtml, kChromeHtml + arraysize(kChromeHtml) - 1,
+ command_line_lower.begin() + pos - kOffset)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
#endif // OS_WIN
// Register the invalid param handler and pure call handler to be able to
@@ -227,6 +260,12 @@
#endif
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
+#if defined(OS_WIN)
+ // Must do this before any other usage of command line!
+ if (::IncorrectChromeHtmlArguments(parsed_command_line.command_line_string()))
+ return 1;
+#endif
+
SetupCRT(parsed_command_line);
// Initialize the Chrome path provider.
« 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