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

Unified Diff: mojo/public/rust/src/bindings/macros.rs

Issue 2220183003: Rust: Add validation to decode (Closed) Base URL: git@github.com:domokit/mojo.git@coder-testing
Patch Set: Update from upstream branches (fixed arrays, validation code, etc.) 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/rust/src/bindings/encoding.rs ('k') | mojo/public/rust/src/bindings/message.rs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/rust/src/bindings/macros.rs
diff --git a/mojo/public/rust/src/bindings/macros.rs b/mojo/public/rust/src/bindings/macros.rs
index 62b7274120b8f4b29dd7842b9b8161060376fe1b..49fb05a39af89352a285f9f6c7103081ae98e72e 100644
--- a/mojo/public/rust/src/bindings/macros.rs
+++ b/mojo/public/rust/src/bindings/macros.rs
@@ -30,12 +30,19 @@ macro_rules! impl_encodable_for_pointer {
}
self.encode_new(encoder, context);
}
- fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $crate::bindings::encoding::Context) -> Self {
+ fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $crate::bindings::encoding::Context) -> Result<Self, ValidationError> {
let ptr = {
let state = decoder.get_mut(&context);
- state.decode_pointer()
+ match state.decode_pointer() {
+ Some(ptr) => ptr,
+ None => return Err(ValidationError::IllegalPointer),
+ }
};
- Self::decode_new(decoder, context, ptr)
+ if ptr == $crate::bindings::mojom::MOJOM_NULL_POINTER {
+ Err(ValidationError::UnexpectedNullPointer)
+ } else {
+ Self::decode_new(decoder, context, ptr)
+ }
}
};
}
@@ -71,7 +78,7 @@ macro_rules! impl_encodable_for_union {
self.inline_encode(encoder, context.set_is_union(true));
}
}
- fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $crate::bindings::encoding::Context) -> Self {
+ fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $crate::bindings::encoding::Context) -> Result<Self, ValidationError> {
if context.is_union() {
Self::nested_decode(decoder, context)
} else {
@@ -111,14 +118,13 @@ macro_rules! impl_encodable_for_interface {
state.encode(pos as i32);
state.encode(Self::version() as u32);
}
- fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $crate::bindings::encoding::Context) -> Self {
- // TODO(mknyszek): verify version
+ fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $crate::bindings::encoding::Context) -> Result<Self, ValidationError> {
let (handle_index, _version) = {
let mut state = decoder.get_mut(&context);
(state.decode::<i32>(), state.decode::<u32>())
};
- Self::new(decoder.claim_handle::<$crate::system::message_pipe::MessageEndpoint>(handle_index))
+ let handle = try!(decoder.claim_handle::<$crate::system::message_pipe::MessageEndpoint>(handle_index));
+ Ok(Self::new(handle))
}
}
}
-
« no previous file with comments | « mojo/public/rust/src/bindings/encoding.rs ('k') | mojo/public/rust/src/bindings/message.rs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698