Sanitize enclosing quotes around paths in policies.

BUG=80211
TEST=unit_tests PolicyPathParser*

Review URL: http://codereview.chromium.org/6966032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86807 0039d316-1c4b-4281-b951-d872f2087c98
parent df4ff5ba
...@@ -38,6 +38,15 @@ const MacFolderNamesToSPDMaping mac_folder_mapping[] = { ...@@ -38,6 +38,15 @@ const MacFolderNamesToSPDMaping mac_folder_mapping[] = {
FilePath::StringType ExpandPathVariables( FilePath::StringType ExpandPathVariables(
const FilePath::StringType& untranslated_string) { const FilePath::StringType& untranslated_string) {
FilePath::StringType result(untranslated_string); FilePath::StringType result(untranslated_string);
if (result.length() == 0)
return result;
// Sanitize quotes in case of any around the whole string.
if (result.length() > 1 &&
((result[0] == '"' && result[result.length() - 1] == '"') ||
(result[0] == '\'' && result[result.length() - 1] == '\''))) {
// Strip first and last char which should be matching quotes now.
result = result.substr(1, result.length() - 2);
}
// First translate all path variables we recognize. // First translate all path variables we recognize.
for (size_t i = 0; i < arraysize(mac_folder_mapping); ++i) { for (size_t i = 0; i < arraysize(mac_folder_mapping); ++i) {
size_t position = result.find(mac_folder_mapping[i].name); size_t position = result.find(mac_folder_mapping[i].name);
......
...@@ -20,6 +20,15 @@ const char* kUserNamePolicyVarName = "${user_name}"; ...@@ -20,6 +20,15 @@ const char* kUserNamePolicyVarName = "${user_name}";
FilePath::StringType ExpandPathVariables( FilePath::StringType ExpandPathVariables(
const FilePath::StringType& untranslated_string) { const FilePath::StringType& untranslated_string) {
FilePath::StringType result(untranslated_string); FilePath::StringType result(untranslated_string);
if (result.length() == 0)
return result;
// Sanitize quotes in case of any around the whole string.
if (result.length() > 1 &&
((result[0] == '"' && result[result.length() - 1] == '"') ||
(result[0] == '\'' && result[result.length() - 1] == '\''))) {
// Strip first and last char which should be matching quotes now.
result = result.substr(1, result.length() - 2);
}
// Translate two special variables ${user_name} and ${machine_name} // Translate two special variables ${user_name} and ${machine_name}
size_t position = result.find(kUserNamePolicyVarName); size_t position = result.find(kUserNamePolicyVarName);
if (position != std::string::npos) { if (position != std::string::npos) {
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -33,6 +33,16 @@ TEST_F(PolicyPathParserTests, AllPlatformVariables) { ...@@ -33,6 +33,16 @@ TEST_F(PolicyPathParserTests, AllPlatformVariables) {
path_parser::ExpandPathVariables(unknown_vars); path_parser::ExpandPathVariables(unknown_vars);
ASSERT_EQ(unknown_vars_result, unknown_vars); ASSERT_EQ(unknown_vars_result, unknown_vars);
// Trim quotes around, but not inside paths. Test against bug 80211.
FilePath::StringType no_quotes(FILE_PATH_LITERAL("//$C/\"a\"/$path"));
FilePath::StringType single_quotes(FILE_PATH_LITERAL("'//$C/\"a\"/$path'"));
FilePath::StringType double_quotes(FILE_PATH_LITERAL("\"//$C/\"a\"/$path\""));
FilePath::StringType quotes_result =
path_parser::ExpandPathVariables(single_quotes);
ASSERT_EQ(quotes_result, no_quotes);
quotes_result = path_parser::ExpandPathVariables(double_quotes);
ASSERT_EQ(quotes_result, no_quotes);
// Both should have been substituted. // Both should have been substituted.
FilePath::StringType vars(FILE_PATH_LITERAL("${user_name}${machine_name}")); FilePath::StringType vars(FILE_PATH_LITERAL("${user_name}${machine_name}"));
FilePath::StringType vars_result = path_parser::ExpandPathVariables(vars); FilePath::StringType vars_result = path_parser::ExpandPathVariables(vars);
......
...@@ -44,6 +44,15 @@ const WinFolderNamesToCSIDLMapping win_folder_mapping[] = { ...@@ -44,6 +44,15 @@ const WinFolderNamesToCSIDLMapping win_folder_mapping[] = {
FilePath::StringType ExpandPathVariables( FilePath::StringType ExpandPathVariables(
const FilePath::StringType& untranslated_string) { const FilePath::StringType& untranslated_string) {
FilePath::StringType result(untranslated_string); FilePath::StringType result(untranslated_string);
if (result.length() == 0)
return result;
// Sanitize quotes in case of any around the whole string.
if (result.length() > 1 &&
((result[0] == L'"' && result[result.length() - 1] == L'"') ||
(result[0] == L'\'' && result[result.length() - 1] == L'\''))) {
// Strip first and last char which should be matching quotes now.
result = result.substr(1, result.length() - 2);
}
// First translate all path variables we recognize. // First translate all path variables we recognize.
for (int i = 0; i < arraysize(win_folder_mapping); ++i) { for (int i = 0; i < arraysize(win_folder_mapping); ++i) {
size_t position = result.find(win_folder_mapping[i].name); size_t position = result.find(win_folder_mapping[i].name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment