From cf8442b12cf7d1a1375c4d80ee9df3e6424894a4 Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 14 Aug 2020 01:54:19 -0700 Subject: [PATCH] Add bounds checks to getSize() and getAddress() It's all too easy for someone to pass in a bad index and index out of bounds, so we need to prevent that from happening. --- desktop_version/src/BinaryBlob.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/desktop_version/src/BinaryBlob.cpp b/desktop_version/src/BinaryBlob.cpp index 18f2fa2c..a8e94825 100644 --- a/desktop_version/src/BinaryBlob.cpp +++ b/desktop_version/src/BinaryBlob.cpp @@ -5,6 +5,8 @@ #include #include +#include "UtilityClass.h" + binaryBlob::binaryBlob() { numberofHeaders = 0; @@ -159,11 +161,21 @@ int binaryBlob::getIndex(const char* _name) int binaryBlob::getSize(int _index) { + if (!INBOUNDS_ARR(_index, m_headers)) + { + puts("getSize() out-of-bounds!"); + return 0; + } return m_headers[_index].size; } char* binaryBlob::getAddress(int _index) { + if (!INBOUNDS_ARR(_index, m_memblocks)) + { + puts("getAddress() out-of-bounds!"); + return NULL; + } return m_memblocks[_index]; }