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

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

Issue 11183029: Don't reject extension list policies with invalid entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment. Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/policy/configuration_policy_handler.h" 5 #include "chrome/browser/policy/configuration_policy_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 bool ExtensionListPolicyHandler::CheckPolicySettings( 221 bool ExtensionListPolicyHandler::CheckPolicySettings(
222 const PolicyMap& policies, 222 const PolicyMap& policies,
223 PolicyErrorMap* errors) { 223 PolicyErrorMap* errors) {
224 return CheckAndGetList(policies, errors, NULL); 224 return CheckAndGetList(policies, errors, NULL);
225 } 225 }
226 226
227 void ExtensionListPolicyHandler::ApplyPolicySettings( 227 void ExtensionListPolicyHandler::ApplyPolicySettings(
228 const PolicyMap& policies, 228 const PolicyMap& policies,
229 PrefValueMap* prefs) { 229 PrefValueMap* prefs) {
230 const Value* value = policies.GetValue(policy_name()); 230 scoped_ptr<base::ListValue> list;
231 if (value) 231 PolicyErrorMap errors;
232 prefs->SetValue(pref_path(), value->DeepCopy()); 232 if (CheckAndGetList(policies, &errors, &list) && list)
233 prefs->SetValue(pref_path(), list.release());
233 } 234 }
234 235
235 const char* ExtensionListPolicyHandler::pref_path() const { 236 const char* ExtensionListPolicyHandler::pref_path() const {
236 return pref_path_; 237 return pref_path_;
237 } 238 }
238 239
239 bool ExtensionListPolicyHandler::CheckAndGetList( 240 bool ExtensionListPolicyHandler::CheckAndGetList(
240 const PolicyMap& policies, 241 const PolicyMap& policies,
241 PolicyErrorMap* errors, 242 PolicyErrorMap* errors,
242 const base::ListValue** extension_ids) { 243 scoped_ptr<base::ListValue>* extension_ids) {
243 if (extension_ids) 244 if (extension_ids)
244 *extension_ids = NULL; 245 extension_ids->reset();
245 246
246 const base::Value* value = NULL; 247 const base::Value* value = NULL;
247 if (!CheckAndGetValue(policies, errors, &value)) 248 if (!CheckAndGetValue(policies, errors, &value))
248 return false; 249 return false;
249 250
250 if (!value) 251 if (!value)
251 return true; 252 return true;
252 253
253 const base::ListValue* list_value = NULL; 254 const base::ListValue* list_value = NULL;
254 if (!value->GetAsList(&list_value)) { 255 if (!value->GetAsList(&list_value)) {
255 NOTREACHED(); 256 NOTREACHED();
256 return false; 257 return false;
257 } 258 }
258 259
259 // Check that the list contains valid extension ID strings only. 260 // Filter the list, rejecting any invalid extension IDs.
261 scoped_ptr<base::ListValue> filtered_list(new base::ListValue());
260 for (base::ListValue::const_iterator entry(list_value->begin()); 262 for (base::ListValue::const_iterator entry(list_value->begin());
261 entry != list_value->end(); ++entry) { 263 entry != list_value->end(); ++entry) {
262 std::string id; 264 std::string id;
263 if (!(*entry)->GetAsString(&id)) { 265 if (!(*entry)->GetAsString(&id)) {
264 errors->AddError(policy_name(), 266 errors->AddError(policy_name(),
265 entry - list_value->begin(), 267 entry - list_value->begin(),
266 IDS_POLICY_TYPE_ERROR, 268 IDS_POLICY_TYPE_ERROR,
267 ValueTypeToString(base::Value::TYPE_STRING)); 269 ValueTypeToString(base::Value::TYPE_STRING));
268 return false; 270 continue;
269 } 271 }
270 if (!(allow_wildcards_ && id == "*") && 272 if (!(allow_wildcards_ && id == "*") &&
271 !extensions::Extension::IdIsValid(id)) { 273 !extensions::Extension::IdIsValid(id)) {
272 errors->AddError(policy_name(), 274 errors->AddError(policy_name(),
273 entry - list_value->begin(), 275 entry - list_value->begin(),
274 IDS_POLICY_VALUE_FORMAT_ERROR); 276 IDS_POLICY_VALUE_FORMAT_ERROR);
275 return false; 277 continue;
276 } 278 }
279 filtered_list->Append(base::Value::CreateStringValue(id));
277 } 280 }
278 281
279 if (extension_ids) 282 if (extension_ids)
280 *extension_ids = list_value; 283 *extension_ids = filtered_list.Pass();
281 284
282 return true; 285 return true;
283 } 286 }
284 287
285 // ExtensionURLPatternListPolicyHandler implementation ------------------------- 288 // ExtensionURLPatternListPolicyHandler implementation -------------------------
286 289
287 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( 290 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler(
288 const char* policy_name, 291 const char* policy_name,
289 const char* pref_path) 292 const char* pref_path)
290 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), 293 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST),
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 errors->AddError(policy_name(), 1286 errors->AddError(policy_name(),
1284 IDS_POLICY_OUT_OF_RANGE_ERROR, 1287 IDS_POLICY_OUT_OF_RANGE_ERROR,
1285 base::IntToString(restore_value)); 1288 base::IntToString(restore_value));
1286 } 1289 }
1287 } 1290 }
1288 } 1291 }
1289 return true; 1292 return true;
1290 } 1293 }
1291 1294
1292 } // namespace policy 1295 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler.h ('k') | chrome/browser/policy/configuration_policy_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698