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

Side by Side Diff: chrome/browser/policy/policy_path_parser_win.cc

Issue 6966032: Sanitize enclosing quotes around paths in policies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed one forgotten copyright header. Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/policy_path_parser_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <shlobj.h> 5 #include <shlobj.h>
6 6
7 #include "chrome/browser/policy/policy_path_parser.h" 7 #include "chrome/browser/policy/policy_path_parser.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 26 matching lines...) Expand all
37 { kWinLocalAppDataFolderVarName, CSIDL_LOCAL_APPDATA}, 37 { kWinLocalAppDataFolderVarName, CSIDL_LOCAL_APPDATA},
38 { kWinRoamingAppDataFolderVarName, CSIDL_APPDATA}, 38 { kWinRoamingAppDataFolderVarName, CSIDL_APPDATA},
39 { kWinDocumentsFolderVarName, CSIDL_PERSONAL} 39 { kWinDocumentsFolderVarName, CSIDL_PERSONAL}
40 }; 40 };
41 41
42 // Replaces all variable occurances in the policy string with the respective 42 // Replaces all variable occurances in the policy string with the respective
43 // system settings values. 43 // system settings values.
44 FilePath::StringType ExpandPathVariables( 44 FilePath::StringType ExpandPathVariables(
45 const FilePath::StringType& untranslated_string) { 45 const FilePath::StringType& untranslated_string) {
46 FilePath::StringType result(untranslated_string); 46 FilePath::StringType result(untranslated_string);
47 if (result.length() == 0)
48 return result;
49 // Sanitize quotes in case of any around the whole string.
50 if (result.length() > 1 &&
51 ((result[0] == L'"' && result[result.length() - 1] == L'"') ||
52 (result[0] == L'\'' && result[result.length() - 1] == L'\''))) {
53 // Strip first and last char which should be matching quotes now.
54 result = result.substr(1, result.length() - 2);
55 }
47 // First translate all path variables we recognize. 56 // First translate all path variables we recognize.
48 for (int i = 0; i < arraysize(win_folder_mapping); ++i) { 57 for (int i = 0; i < arraysize(win_folder_mapping); ++i) {
49 size_t position = result.find(win_folder_mapping[i].name); 58 size_t position = result.find(win_folder_mapping[i].name);
50 if (position != std::wstring::npos) { 59 if (position != std::wstring::npos) {
51 WCHAR path[MAX_PATH]; 60 WCHAR path[MAX_PATH];
52 ::SHGetSpecialFolderPath(0, path, win_folder_mapping[i].id, false); 61 ::SHGetSpecialFolderPath(0, path, win_folder_mapping[i].id, false);
53 std::wstring path_string(path); 62 std::wstring path_string(path);
54 result.replace(position, wcslen(win_folder_mapping[i].name), path_string); 63 result.replace(position, wcslen(win_folder_mapping[i].name), path_string);
55 } 64 }
56 } 65 }
(...skipping 21 matching lines...) Expand all
78 result.replace( 87 result.replace(
79 position, wcslen(kMachineNamePolicyVarName), machinename_string); 88 position, wcslen(kMachineNamePolicyVarName), machinename_string);
80 } 89 }
81 } 90 }
82 return result; 91 return result;
83 } 92 }
84 93
85 } // namespace path_parser 94 } // namespace path_parser
86 95
87 } // namespace policy 96 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_path_parser_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698