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)