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

Unified Diff: mojo/public/cpp/bindings/lib/bindings_serialization.cc

Issue 307353009: Mojo cpp bindings: report the reason of validation failure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/lib/bindings_serialization.cc
diff --git a/mojo/public/cpp/bindings/lib/bindings_serialization.cc b/mojo/public/cpp/bindings/lib/bindings_serialization.cc
index c1114c0edba51df01430f408915b7141ddca37e0..d341b21446cd5154caf7a3813988c5091540be99 100644
--- a/mojo/public/cpp/bindings/lib/bindings_serialization.cc
+++ b/mojo/public/cpp/bindings/lib/bindings_serialization.cc
@@ -8,6 +8,7 @@
#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
#include "mojo/public/cpp/bindings/lib/bounds_checker.h"
+#include "mojo/public/cpp/bindings/lib/validation_errors.h"
namespace mojo {
namespace internal {
@@ -83,21 +84,30 @@ bool ValidateStructHeader(const void* data,
uint32_t min_num_bytes,
uint32_t min_num_fields,
BoundsChecker* bounds_checker) {
- if (!IsAligned(data))
+ if (!IsAligned(data)) {
+ ReportValidationError(VALIDATION_ERROR_MISALIGNED_OBJECT);
return false;
- if (!bounds_checker->IsValidRange(data, sizeof(StructHeader)))
+ }
+ if (!bounds_checker->IsValidRange(data, sizeof(StructHeader))) {
+ ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE);
return false;
+ }
const StructHeader* header = static_cast<const StructHeader*>(data);
// TODO(yzshen): Currently our binding code cannot handle structs of smaller
// size or with fewer fields than the version that it sees. That needs to be
// changed in order to provide backward compatibility.
- if (header->num_bytes < min_num_bytes || header->num_fields < min_num_fields)
+ if (header->num_bytes < min_num_bytes ||
+ header->num_fields < min_num_fields) {
+ ReportValidationError(VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
return false;
+ }
- if (!bounds_checker->ClaimMemory(data, header->num_bytes))
+ if (!bounds_checker->ClaimMemory(data, header->num_bytes)) {
+ ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE);
return false;
+ }
return true;
}
« no previous file with comments | « mojo/public/cpp/bindings/lib/array_internal.cc ('k') | mojo/public/cpp/bindings/lib/message_header_validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698