From 484a360792f42b696baaacd4d6711c204b1ace50 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 18 Apr 2024 02:58:19 +0300 Subject: [PATCH] Add a safety measure for string loading in BGSM --- components/bgsm/stream.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/bgsm/stream.cpp b/components/bgsm/stream.cpp index d8434fcb8a..00cc382d3f 100644 --- a/components/bgsm/stream.cpp +++ b/components/bgsm/stream.cpp @@ -41,6 +41,9 @@ namespace Bgsm std::string BGSMStream::getSizedString(size_t length) { + // Prevent potential memory allocation freezes; strings this long are not expected in BGSM + if (length > 1024) + throw std::runtime_error("Requested string length is too large: " + std::to_string(length)); std::string str(length, '\0'); mStream->read(str.data(), length); if (mStream->bad())