From 152e69a6d1bfd782a04988d631703639656472e8 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sat, 25 Dec 2021 16:26:34 -0500 Subject: [PATCH] bytevector: validate length in get() Don't allow a pointer to T to be taken from a ByteVector that is not at least sizeof(T) bytes long. Signed-off-by: Zygo Blaxell --- include/crucible/bytevector.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/crucible/bytevector.h b/include/crucible/bytevector.h index 28c5028..469f3d1 100644 --- a/include/crucible/bytevector.h +++ b/include/crucible/bytevector.h @@ -1,6 +1,8 @@ #ifndef _CRUCIBLE_BYTEVECTOR_H_ #define _CRUCIBLE_BYTEVECTOR_H_ +#include + #include #include #include @@ -69,6 +71,7 @@ namespace crucible { T* ByteVector::get() const { + THROW_CHECK2(out_of_range, size(), sizeof(T), size() >= sizeof(T)); return reinterpret_cast(data()); } }