diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-06 10:25:35 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-06 10:25:35 +0000 |
commit | 02c8796f86e238be73fecd15b894724d58a96f4d (patch) | |
tree | 24c98fc21034b55c54d7f907a7977d0680d10322 /base/command_line.cc | |
parent | 095214d9fd4f7dc5b9218d3fe78cf3ee08f480b8 (diff) | |
download | chromium_src-02c8796f86e238be73fecd15b894724d58a96f4d.zip chromium_src-02c8796f86e238be73fecd15b894724d58a96f4d.tar.gz chromium_src-02c8796f86e238be73fecd15b894724d58a96f4d.tar.bz2 |
Add -- as a command line switch parsing terminator. This allows you to launch chrome to a given URL safely, without having to validate the URL and worry it might be interpreted as a dangerous command line argument.
Review URL: http://codereview.chromium.org/6480
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2876 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/command_line.cc')
-rw-r--r-- | base/command_line.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/base/command_line.cc b/base/command_line.cc index 848ac6b..11a475d 100644 --- a/base/command_line.cc +++ b/base/command_line.cc @@ -29,6 +29,7 @@ const wchar_t* const CommandLine::kSwitchPrefixes[] = {L"--", L"-"}; #endif const wchar_t CommandLine::kSwitchValueSeparator[] = L"="; +const wchar_t CommandLine::kSwitchTerminator[] = L"--"; // Needed to avoid a typecast on the tolower() function pointer in Lowercase(). // MSVC accepts it as-is but GCC requires the typecast. @@ -88,10 +89,21 @@ class CommandLine::Data { // Populate program_ with the trimmed version of the first arg. TrimWhitespace(args[0], TRIM_ALL, &program_); + bool parse_switches = true; for (int i = 1; i < num_args; ++i) { wstring arg; TrimWhitespace(args[i], TRIM_ALL, &arg); + if (!parse_switches) { + loose_values_.push_back(arg); + continue; + } + + if (arg == kSwitchTerminator) { + parse_switches = false; + continue; + } + wstring switch_string; wstring switch_value; if (IsSwitch(arg, &switch_string, &switch_value)) { @@ -113,11 +125,22 @@ class CommandLine::Data { program_ = base::SysNativeMBToWide(argv[0]); command_line_string_ = program_; + bool parse_switches = true; for (int i = 1; i < argc; ++i) { std::wstring arg = base::SysNativeMBToWide(argv[i]); command_line_string_.append(L" "); command_line_string_.append(arg); + if (!parse_switches) { + loose_values_.push_back(arg); + continue; + } + + if (arg == kSwitchTerminator) { + parse_switches = false; + continue; + } + wstring switch_string; wstring switch_value; if (IsSwitch(arg, &switch_string, &switch_value)) { |