From a1a71ee031341ed2870b5b0fca5722e5145b96e6 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 13 Jun 2022 04:00:41 +0300 Subject: [PATCH] Validate sub-str range. --- module/Library/RegEx.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/module/Library/RegEx.hpp b/module/Library/RegEx.hpp index a77ac19e..bb47b121 100644 --- a/module/Library/RegEx.hpp +++ b/module/Library/RegEx.hpp @@ -117,6 +117,11 @@ struct RxMatch */ [[nodiscard]] LightObj SubStr(StackStrF & str) const { + if ((mOffset + mLength) > str.mLen) + { + STHROWF("Rx: Match is outside the range of the specified string."); + } + // Return the sub-string return LightObj{str.mPtr + mOffset, mLength}; } }; @@ -371,6 +376,12 @@ struct RxMatches [[nodiscard]] LightObj SubStr(SQInteger i, StackStrF & str) const { const RxMatch & m = ValidIdx(i)[i]; + // Check if match is within range + if ((m.mOffset + m.mLength) > str.mLen) + { + STHROWF("Rx: Match is outside the range of the specified string."); + } + // Return the sub-string return LightObj{str.mPtr + m.mOffset, m.mLength}; } };