[openjk] 04/11: game: If strings are too long, raise error instead of assuming 0 length

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 9c38824c462933210810fad193576fbe1c744c95
Author: Simon McVittie <smcv at debian.org>
Date:   Sat Jan 21 15:12:50 2017 +0000

    game: If strings are too long, raise error instead of assuming 0 length
    
    Signed-off-by: Simon McVittie <smcv at debian.org>
---
 code/game/G_Timer.cpp         | 14 ++++++--------
 code/game/Q3_Interface.cpp    |  6 +++---
 code/game/g_roff.cpp          |  4 +++-
 codeJK2/game/Q3_Registers.cpp |  6 +++---
 codeJK2/game/g_roff.cpp       |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/code/game/G_Timer.cpp b/code/game/G_Timer.cpp
index 192594d..89ecb94 100644
--- a/code/game/G_Timer.cpp
+++ b/code/game/G_Timer.cpp
@@ -247,16 +247,14 @@ void TIMER_Load( void )
 
 			if (sg_buffer_size < 0 || static_cast<size_t>(sg_buffer_size) >= sizeof(tempBuffer))
 			{
-				sg_buffer_size = 0;
-			}
-			else
-			{
-				std::uninitialized_copy_n(
-					sg_buffer_data,
-					sg_buffer_size,
-					tempBuffer);
+				::G_Error("invalid length for TMID string in saved game: %d\n", sg_buffer_size);
 			}
 
+			std::uninitialized_copy_n(
+				sg_buffer_data,
+				sg_buffer_size,
+				tempBuffer);
+
 			tempBuffer[sg_buffer_size] = '\0';
 
 			saved_game.read_chunk<int32_t>(
diff --git a/code/game/Q3_Interface.cpp b/code/game/Q3_Interface.cpp
index 2c740d4..585167a 100644
--- a/code/game/Q3_Interface.cpp
+++ b/code/game/Q3_Interface.cpp
@@ -7328,7 +7328,7 @@ void CQuake3GameInterface::VariableLoadFloats( varFloat_m &fmap )
 
 		if (idSize < 0 || static_cast<size_t>(idSize) >= sizeof(tempBuffer))
 		{
-			idSize = 0;
+			::G_Error("invalid length for FIDS string in save game: %d bytes\n", idSize);
 		}
 
 		saved_game.read_chunk(
@@ -7378,7 +7378,7 @@ void CQuake3GameInterface::VariableLoadStrings( int type, varString_m &fmap )
 
 		if (idSize < 0 || static_cast<size_t>(idSize) >= sizeof(tempBuffer))
 		{
-			idSize = 0;
+			::G_Error("invalid length for SIDS string in save game: %d bytes\n", idSize);
 		}
 
 		saved_game.read_chunk(
@@ -7394,7 +7394,7 @@ void CQuake3GameInterface::VariableLoadStrings( int type, varString_m &fmap )
 
 		if (idSize < 0 || static_cast<size_t>(idSize) >= sizeof(tempBuffer2))
 		{
-			idSize = 0;
+			::G_Error("invalid length for SVAL string in save game: %d bytes\n", idSize);
 		}
 
 		saved_game.read_chunk(
diff --git a/code/game/g_roff.cpp b/code/game/g_roff.cpp
index 9ec25ad..a337b28 100644
--- a/code/game/g_roff.cpp
+++ b/code/game/g_roff.cpp
@@ -704,7 +704,9 @@ void G_LoadCachedRoffs()
 			len);
 
 		if (len < 0 || static_cast<size_t>(len) >= sizeof(buffer))
-			len = 0;
+		{
+			::G_Error("invalid length for RSTR string in save game: %d bytes\n", len);
+		}
 
 		saved_game.read_chunk(
 			INT_ID('R', 'S', 'T', 'R'),
diff --git a/codeJK2/game/Q3_Registers.cpp b/codeJK2/game/Q3_Registers.cpp
index 25c99cd..f278c09 100644
--- a/codeJK2/game/Q3_Registers.cpp
+++ b/codeJK2/game/Q3_Registers.cpp
@@ -410,7 +410,7 @@ void Q3_VariableLoadFloats( varFloat_m &fmap )
 
 		if (idSize < 0 || static_cast<size_t>(idSize) >= sizeof(tempBuffer))
 		{
-			idSize = 0;
+			::G_Error("invalid length for FIDS string in save game: %d bytes\n", idSize);
 		}
 
 		saved_game.read_chunk(
@@ -460,7 +460,7 @@ void Q3_VariableLoadStrings( int type, varString_m &fmap )
 
 		if (idSize < 0 || static_cast<size_t>(idSize) >= sizeof(tempBuffer))
 		{
-			idSize = 0;
+			::G_Error("invalid length for SIDS string in save game: %d bytes\n", idSize);
 		}
 
 		saved_game.read_chunk(
@@ -476,7 +476,7 @@ void Q3_VariableLoadStrings( int type, varString_m &fmap )
 
 		if (idSize < 0 || static_cast<size_t>(idSize) >= sizeof(tempBuffer2))
 		{
-			idSize = 0;
+			::G_Error("invalid length for SVAL string in save game: %d bytes\n", idSize);
 		}
 
 		saved_game.read_chunk(
diff --git a/codeJK2/game/g_roff.cpp b/codeJK2/game/g_roff.cpp
index b5c0240..b1c9539 100644
--- a/codeJK2/game/g_roff.cpp
+++ b/codeJK2/game/g_roff.cpp
@@ -680,7 +680,7 @@ void G_LoadCachedRoffs()
 
 		if (len < 0 || static_cast<size_t>(len) >= sizeof(buffer))
 		{
-			len = 0;
+			::G_Error("invalid length for RSTR string in save game: %d bytes\n", len);
 		}
 
 		saved_game.read_chunk(

-- 
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