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

Unified Diff: services/authentication/accounts_db_manager.cc

Issue 1800753005: C++ bindings: A struct's Deserialize() now does validation before deserializing. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Address comments. DeserializeWithoutValidation returns void, doesn't take in buf_size. Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: services/authentication/accounts_db_manager.cc
diff --git a/services/authentication/accounts_db_manager.cc b/services/authentication/accounts_db_manager.cc
index f7cd3fecc9167768b1abf2970e01f1041455031c..fe0a1ad02d0cae21cbcf5f079ea00338f0fcc4cc 100644
--- a/services/authentication/accounts_db_manager.cc
+++ b/services/authentication/accounts_db_manager.cc
@@ -181,20 +181,11 @@ void AccountsDbManager::OnCredentialsFileReadResponse(
if (bytes_read.size() != 0) {
// Deserialize data from file
const char* data = reinterpret_cast<const char*>(&bytes_read[0]);
-
- // Validate the file contents before deserializing
- mojo::internal::BoundsChecker bounds_checker(data, bytes_read.size(), 0);
- std::string error;
- mojo::internal::ValidationError verror =
- internal::CredentialStore_Data::Validate(data, &bounds_checker, &error);
- if (verror != mojo::internal::ValidationError::NONE) {
- LOG(ERROR) << "Validation() error on accounts db ["
- << ValidationErrorToString(verror) << "][" << error << "]";
+ if (!creds_store_.Deserialize((void*)data, bytes_read.size())) {
+ LOG(ERROR) << "Deserialize() error on accounts db.";
error_ = CREDENTIALS_DB_VALIDATE_ERROR;
return;
}
-
- creds_store_.Deserialize((void*)data);
// When we have multiple versions, this is not a fatal error, but a sign
// that we need to update (or reinitialize) the db.
CHECK_EQ(creds_store_.version, kCredsDbVersion);
@@ -219,17 +210,12 @@ void AccountsDbManager::OnAuthorizationsFileReadResponse(
if (bytes_read.size() != 0) {
// Deserialize data from file
const char* data = reinterpret_cast<const char*>(&bytes_read[0]);
-
- // Validate the file contents before deserializing
- mojo::internal::BoundsChecker bounds_checker(data, bytes_read.size(), 0);
- if (internal::Db_Data::Validate(data, &bounds_checker, nullptr) !=
- mojo::internal::ValidationError::NONE) {
- LOG(ERROR) << "Validation() error on auth db.";
+ if (!auth_grants_.Deserialize((void*)data, bytes_read.size())) {
+ LOG(ERROR) << "Deserialize() error on auth db.";
error_ = AUTHORIZATIONS_DB_VALIDATE_ERROR;
return;
}
- auth_grants_.Deserialize((void*)data);
// When we have multiple versions, this is not a fatal error, but a sign
// that we need to update (or reinitialize) the db.
CHECK_EQ(auth_grants_.version, kAuthDbVersion);

Powered by Google App Engine
This is Rietveld 408576698