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

Side by Side Diff: extensions/common/extension_api.cc

Issue 2254383002: Signal extension API schema corruption to the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak comments Created 4 years, 4 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
« no previous file with comments | « extensions/common/extension_api.h ('k') | extensions/common/extension_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/common/extension_api.h" 5 #include "extensions/common/extension_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 std::unique_ptr<base::ListValue> LoadSchemaList( 48 std::unique_ptr<base::ListValue> LoadSchemaList(
49 const std::string& name, 49 const std::string& name,
50 const base::StringPiece& schema) { 50 const base::StringPiece& schema) {
51 std::string error_message; 51 std::string error_message;
52 std::unique_ptr<base::Value> result(base::JSONReader::ReadAndReturnError( 52 std::unique_ptr<base::Value> result(base::JSONReader::ReadAndReturnError(
53 schema, 53 schema,
54 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN, // options 54 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN, // options
55 NULL, // error code 55 NULL, // error code
56 &error_message)); 56 &error_message));
57 57
58 // Tracking down http://crbug.com/121424 58 #if DCHECK_IS_ON()
59 char buf[128]; 59 // |schema| comes from JSON hard-coded to the Chrome binary, so in principle
60 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", 60 // failure to parse indicates we generated corrupted JSON, but in practice
61 name.c_str(), 61 // corruption of the Chrome binary (e.g. disk errors) can also break it.
62 result.get() ? result->GetType() : -1, 62 // See http://crbug.com/121424.
63 error_message.c_str()); 63 if (!result || !result->IsType(base::Value::TYPE_LIST)) {
64 char buf[128];
65 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", name.c_str(),
dcheng 2016/08/23 05:07:08 Out of curiosity, why not just use base::StringPri
Devlin 2016/08/23 19:34:16 My guess is because we don't know how long error_m
dcheng 2016/08/24 00:12:21 There's a printf specifier to limit the max length
Wez 2016/08/24 00:24:13 Actually it's just that that's what the original c
66 result.get() ? result->GetType() : -1,
67 error_message.c_str());
64 68
65 CHECK(result.get()) << error_message << " for schema " << schema; 69 DCHECK(result) << "JSON parse failed: " << buf;
66 CHECK(result->IsType(base::Value::TYPE_LIST)) << " for schema " << schema; 70 DCHECK(result->IsType(base::Value::TYPE_LIST)) << "JSON wrong type: "
71 << buf;
72 }
73 #endif // DCHECK_IS_ON()
74
75 // From() returns null if passed a null or non-list value.
67 return base::ListValue::From(std::move(result)); 76 return base::ListValue::From(std::move(result));
68 } 77 }
69 78
70 const base::DictionaryValue* FindListItem(const base::ListValue* list, 79 const base::DictionaryValue* FindListItem(const base::ListValue* list,
71 const std::string& property_name, 80 const std::string& property_name,
72 const std::string& property_value) { 81 const std::string& property_value) {
73 for (size_t i = 0; i < list->GetSize(); ++i) { 82 for (size_t i = 0; i < list->GetSize(); ++i) {
74 const base::DictionaryValue* item = NULL; 83 const base::DictionaryValue* item = NULL;
75 CHECK(list->GetDictionary(i, &item)) 84 CHECK(list->GetDictionary(i, &item))
76 << property_value << "/" << property_name; 85 << property_value << "/" << property_name;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 g_shared_instance_for_test = testing_api; 216 g_shared_instance_for_test = testing_api;
208 } 217 }
209 218
210 ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() { 219 ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() {
211 g_shared_instance_for_test = original_api_; 220 g_shared_instance_for_test = original_api_;
212 } 221 }
213 222
214 void ExtensionAPI::LoadSchema(const std::string& name, 223 void ExtensionAPI::LoadSchema(const std::string& name,
215 const base::StringPiece& schema) { 224 const base::StringPiece& schema) {
216 std::unique_ptr<base::ListValue> schema_list(LoadSchemaList(name, schema)); 225 std::unique_ptr<base::ListValue> schema_list(LoadSchemaList(name, schema));
226 if (!schema_list)
227 return;
228
217 std::string schema_namespace; 229 std::string schema_namespace;
218 extensions::ExtensionsClient* extensions_client = 230 extensions::ExtensionsClient* extensions_client =
219 extensions::ExtensionsClient::Get(); 231 extensions::ExtensionsClient::Get();
220 DCHECK(extensions_client); 232 DCHECK(extensions_client);
221 while (!schema_list->empty()) { 233 while (!schema_list->empty()) {
222 std::unique_ptr<base::DictionaryValue> schema; 234 std::unique_ptr<base::DictionaryValue> schema;
223 { 235 {
224 std::unique_ptr<base::Value> val; 236 std::unique_ptr<base::Value> val;
225 schema_list->Erase(schema_list->begin(), &val); 237 schema_list->Erase(schema_list->begin(), &val);
226 schema = base::DictionaryValue::From(std::move(val)); 238 schema = base::DictionaryValue::From(std::move(val));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 LoadSchema(maybe_schema_resource->first, 336 LoadSchema(maybe_schema_resource->first,
325 ReadFromResource(maybe_schema_resource->second)); 337 ReadFromResource(maybe_schema_resource->second));
326 } else if (default_configuration_initialized_ && 338 } else if (default_configuration_initialized_ &&
327 extensions_client->IsAPISchemaGenerated(api_name)) { 339 extensions_client->IsAPISchemaGenerated(api_name)) {
328 LoadSchema(api_name, extensions_client->GetAPISchema(api_name)); 340 LoadSchema(api_name, extensions_client->GetAPISchema(api_name));
329 } else { 341 } else {
330 return NULL; 342 return NULL;
331 } 343 }
332 344
333 maybe_schema = schemas_.find(api_name); 345 maybe_schema = schemas_.find(api_name);
334 CHECK(schemas_.end() != maybe_schema); 346 // If the schema failed to load then return null for it, rather than
347 // crashing, so that the browser can be notified of the problem.
348 // See http://crbug.com/121424.
349 if (schemas_.end() == maybe_schema)
350 return NULL;
351
335 result = maybe_schema->second.get(); 352 result = maybe_schema->second.get();
336 } 353 }
337 354
338 if (!child_name.empty()) 355 if (!child_name.empty())
339 result = GetSchemaChild(result, child_name); 356 result = GetSchemaChild(result, child_name);
340 357
341 return result; 358 return result;
342 } 359 }
343 360
344 Feature* ExtensionAPI::GetFeatureDependency(const std::string& full_name) { 361 Feature* ExtensionAPI::GetFeatureDependency(const std::string& full_name) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 return result; 400 return result;
384 } 401 }
385 402
386 size_t last_dot_index = api_name_candidate.rfind('.'); 403 size_t last_dot_index = api_name_candidate.rfind('.');
387 if (last_dot_index == std::string::npos) 404 if (last_dot_index == std::string::npos)
388 break; 405 break;
389 406
390 api_name_candidate = api_name_candidate.substr(0, last_dot_index); 407 api_name_candidate = api_name_candidate.substr(0, last_dot_index);
391 } 408 }
392 409
393 *child_name = ""; 410 if (child_name)
411 *child_name = "";
412
394 return std::string(); 413 return std::string();
395 } 414 }
396 415
397 } // namespace extensions 416 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/extension_api.h ('k') | extensions/common/extension_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698