From f13f34ffe3e5d02f8970aedd1dbfdeaba7523222 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Sun, 5 Oct 2025 02:58:13 +0000 Subject: [PATCH] INI: Ensure buffer is null-terminated to prevent buffer overruns --- Generals/Code/GameEngine/Source/Common/INI/INI.cpp | 5 +++++ GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Generals/Code/GameEngine/Source/Common/INI/INI.cpp b/Generals/Code/GameEngine/Source/Common/INI/INI.cpp index 3a20e53d5bb..64209c8dc92 100644 --- a/Generals/Code/GameEngine/Source/Common/INI/INI.cpp +++ b/Generals/Code/GameEngine/Source/Common/INI/INI.cpp @@ -481,6 +481,11 @@ void INI::readLine( void ) INI_MAX_CHARS_PER_LINE) ); } + + // ensure buffer is always null-terminated, even if we hit the buffer limit + // this prevents buffer overruns when the buffer is passed to strtok() and other string functions + if( i >= INI_MAX_CHARS_PER_LINE ) + m_buffer[ INI_MAX_CHARS_PER_LINE - 1 ] = '\0'; } if (s_xfer) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp index e7f7402e7d3..9faff26a2e1 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp @@ -515,6 +515,11 @@ void INI::readLine(void) INI_MAX_CHARS_PER_LINE)); } + + // ensure buffer is always null-terminated, even if we hit the buffer limit + // this prevents buffer overruns when the buffer is passed to strtok() and other string functions + if (p >= m_buffer + INI_MAX_CHARS_PER_LINE) + m_buffer[INI_MAX_CHARS_PER_LINE - 1] = '\0'; } if (s_xfer)