diff options
author | yzshen <yzshen@chromium.org> | 2014-08-25 10:28:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-25 17:30:05 +0000 |
commit | 90017b5f151ca42ffd7a14cfc2eaa08370da9fae (patch) | |
tree | 1a79ec119c89f527c261283273fa2cb82038e704 /mojo/public/cpp/bindings/lib/array_internal.h | |
parent | 895539fab3c573341f0c4e91653dcd32370bcc07 (diff) | |
download | chromium_src-90017b5f151ca42ffd7a14cfc2eaa08370da9fae.zip chromium_src-90017b5f151ca42ffd7a14cfc2eaa08370da9fae.tar.gz chromium_src-90017b5f151ca42ffd7a14cfc2eaa08370da9fae.tar.bz2 |
Mojo C++ bindings: better log messages for some validation errors at the receiver side.
The CL provides more information in the log messages for the following errors:
- Fixed-size array has wrong number of elements.
- non-nullable field is set to null/invalid handle.
The reason to have better log messages for these errors is that they are
triggered when users (of the bindings) provide invalid arguments. The users
probably want to find out what they have done wrong. The other validation errors
are rarer, caused by bugs in the bindings or malicious senders. Providing better
log messages for them is of slightly lower priority.
BUG=324170
TEST=None
Review URL: https://codereview.chromium.org/494943004
Cr-Commit-Position: refs/heads/master@{#291704}
Diffstat (limited to 'mojo/public/cpp/bindings/lib/array_internal.h')
-rw-r--r-- | mojo/public/cpp/bindings/lib/array_internal.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/mojo/public/cpp/bindings/lib/array_internal.h b/mojo/public/cpp/bindings/lib/array_internal.h index 6b0baa0..b512295 100644 --- a/mojo/public/cpp/bindings/lib/array_internal.h +++ b/mojo/public/cpp/bindings/lib/array_internal.h @@ -216,7 +216,11 @@ struct ArraySerializationHelper<Handle, true> { for (uint32_t i = 0; i < header->num_elements; ++i) { if (!element_is_nullable && elements[i].value() == kEncodedInvalidHandleValue) { - ReportValidationError(VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); + ReportValidationError( + VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, + MakeMessageWithArrayIndex( + "invalid handle in array expecting valid handles", + header->num_elements, i).c_str()); return false; } if (!bounds_checker->ClaimHandle(elements[i])) { @@ -280,7 +284,11 @@ struct ArraySerializationHelper<P*, false> { BoundsChecker* bounds_checker) { for (uint32_t i = 0; i < header->num_elements; ++i) { if (!element_is_nullable && !elements[i].offset) { - ReportValidationError(VALIDATION_ERROR_UNEXPECTED_NULL_POINTER); + ReportValidationError( + VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, + MakeMessageWithArrayIndex( + "null in array expecting valid pointers", + header->num_elements, i).c_str()); return false; } if (!ValidateEncodedPointer(&elements[i].offset)) { @@ -356,7 +364,11 @@ class Array_Data { } if (Params::expected_num_elements != 0 && header->num_elements != Params::expected_num_elements) { - ReportValidationError(VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER); + ReportValidationError( + VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, + MakeMessageWithExpectedArraySize( + "fixed-size array has wrong number of elements", + header->num_elements, Params::expected_num_elements).c_str()); return false; } if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { |