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

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

Issue 289333002: Mojo cpp bindings: validation logic for incoming messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify BoundsChecker 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.h
diff --git a/mojo/public/cpp/bindings/lib/bindings_serialization.h b/mojo/public/cpp/bindings/lib/bindings_serialization.h
index 818d69373910ae10067280330837390cb557bec7..884492a1d786043553af435c570c35f5ef4dc1e0 100644
--- a/mojo/public/cpp/bindings/lib/bindings_serialization.h
+++ b/mojo/public/cpp/bindings/lib/bindings_serialization.h
@@ -13,9 +13,17 @@
namespace mojo {
namespace internal {
+class BoundsChecker;
+
+// Please note that this is a different value than |mojo::kInvalidHandleValue|,
+// which is the "decoded" invalid handle.
+const MojoHandle kEncodedInvalidHandleValue = static_cast<MojoHandle>(-1);
+
size_t Align(size_t size);
char* AlignPointer(char* ptr);
+bool IsAligned(const void* ptr);
+
// Pointers are encoded as relative offsets. The offsets are relative to the
// address of where the offset value is stored, such that the pointer may be
// recovered with the expression:
@@ -32,6 +40,10 @@ inline void DecodePointer(const uint64_t* offset, T** ptr) {
*ptr = reinterpret_cast<T*>(const_cast<void*>(DecodePointerRaw(offset)));
}
+// Checks whether decoding the pointer will overflow and produce a pointer
+// smaller than |offset|.
+bool ValidateEncodedPointer(const uint64_t* offset);
+
// Check that the given pointer references memory contained within the message.
bool ValidatePointer(const void* ptr, const Message& message);
@@ -50,6 +62,8 @@ inline void Encode(T* obj, std::vector<Handle>* handles) {
EncodePointer(obj->ptr, &obj->offset);
}
+// TODO(yzshen): Remove all redundant validation during decoding. And make
+// Decode*() functions/methods return void.
template <typename T>
inline bool Decode(T* obj, Message* message) {
DecodePointer(&obj->offset, &obj->ptr);
@@ -62,6 +76,13 @@ inline bool Decode(T* obj, Message* message) {
return true;
}
+// If returns true, this function also claims the memory range of the size
+// specified in the struct header, starting from |data|.
+bool ValidateStructHeader(const void* data,
+ uint32_t min_num_bytes,
+ uint32_t min_num_fields,
+ BoundsChecker* bounds_checker);
+
} // namespace internal
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698