[openjk] 03/11: icarus: Fail to load if buffer would be overflowed, don't just skip

Simon McVittie smcv at debian.org
Sun Jan 22 10:23:05 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository openjk.

commit 9fd2c0b9b837a881e8b89890531e0f13947dda96
Author: Simon McVittie <smcv at debian.org>
Date:   Sat Jan 21 15:10:39 2017 +0000

    icarus: Fail to load if buffer would be overflowed, don't just skip
    
    Unfortunately CIcarus::BufferRead returns void, so we can't
    return a failure state from here, but we can at least print an
    error message.
    
    Signed-off-by: Simon McVittie <smcv at debian.org>
---
 code/icarus/IcarusImplementation.cpp | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/code/icarus/IcarusImplementation.cpp b/code/icarus/IcarusImplementation.cpp
index cc89333..c4e4f1f 100644
--- a/code/icarus/IcarusImplementation.cpp
+++ b/code/icarus/IcarusImplementation.cpp
@@ -720,16 +720,16 @@ int CIcarus::Load()
 
 	if (sg_buffer_size < 0 || static_cast<size_t>(sg_buffer_size) > MAX_BUFFER_SIZE)
 	{
-		sg_buffer_size = 0;
-	}
-	else
-	{
-		std::uninitialized_copy_n(
-			sg_buffer_data,
-			sg_buffer_size,
-			m_byBuffer);
+		DestroyBuffer();
+		game->DebugPrint( IGameInterface::WL_ERROR, "invalid ISEQ length: %d bytes\n", sg_buffer_size);
+		return false;
 	}
 
+	std::uninitialized_copy_n(
+		sg_buffer_data,
+		sg_buffer_size,
+		m_byBuffer);
+
 	//Load all signals
 	if ( LoadSignals() == false )
 	{
@@ -860,16 +860,15 @@ void CIcarus::BufferRead( void *pDstBuff, unsigned long ulNumBytesToRead )
 
 		if (sg_buffer_size < 0 || static_cast<size_t>(sg_buffer_size) > MAX_BUFFER_SIZE)
 		{
-			sg_buffer_size = 0;
-		}
-		else
-		{
-			std::uninitialized_copy_n(
-				sg_buffer_data,
-				sg_buffer_size,
-				m_byBuffer);
+			IGameInterface::GetGame()->DebugPrint( IGameInterface::WL_ERROR, "invalid ISEQ length: %d bytes\n", sg_buffer_size);
+			return;
 		}
 
+		std::uninitialized_copy_n(
+			sg_buffer_data,
+			sg_buffer_size,
+			m_byBuffer);
+
 		m_ulBytesRead = 0;	//reset buffer
 	}
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git



More information about the Pkg-games-commits mailing list