diff --git a/aya-log/aya-log-common/src/lib.rs b/aya-log/aya-log-common/src/lib.rs index b91d07db..c1a5b666 100644 --- a/aya-log/aya-log-common/src/lib.rs +++ b/aya-log/aya-log-common/src/lib.rs @@ -90,7 +90,9 @@ where pub(crate) fn write(&self, mut buf: &mut [u8]) -> Result { let size = mem::size_of::() + mem::size_of::() + self.value.len(); - if buf.len() < size { + // The verifier rejects the program if it can't see that `size` doesn't + // exceed the buffer size. + if size > LOG_BUF_CAPACITY { return Err(()); } @@ -101,6 +103,11 @@ where buf = &mut buf[mem::size_of::()..]; let len = cmp::min(buf.len(), self.value.len()); + // The verifier rejects the program if it can't see that `size` doesn't + // exceed the buffer size. + if len > LOG_BUF_CAPACITY { + return Err(()); + } buf[..len].copy_from_slice(&self.value[..len]); Ok(size) }