[iortcw] 22/89: All: Fix strncpy usage in botlib

Simon McVittie smcv at debian.org
Fri Sep 8 10:44:18 UTC 2017


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

smcv pushed a commit to tag 1.51b
in repository iortcw.

commit fcb3a15d89cfc1df39e53ae4c22736dbd87a2e69
Author: MAN-AT-ARMS <M4N4T4RMS at gmail.com>
Date:   Fri Jun 16 18:01:23 2017 -0400

    All: Fix strncpy usage in botlib
---
 MP/code/botlib/be_aas_main.c | 2 +-
 MP/code/botlib/be_ai_chat.c  | 8 ++++----
 MP/code/botlib/be_ai_goal.c  | 4 ++--
 MP/code/botlib/be_ai_weap.c  | 2 +-
 MP/code/botlib/l_log.c       | 2 +-
 MP/code/botlib/l_precomp.c   | 2 +-
 MP/code/botlib/l_script.c    | 2 +-
 MP/code/botlib/l_struct.c    | 2 +-
 SP/code/botlib/be_aas_main.c | 2 +-
 SP/code/botlib/be_ai_chat.c  | 8 ++++----
 SP/code/botlib/be_ai_goal.c  | 4 ++--
 SP/code/botlib/be_ai_weap.c  | 2 +-
 SP/code/botlib/l_log.c       | 2 +-
 SP/code/botlib/l_precomp.c   | 2 +-
 SP/code/botlib/l_script.c    | 2 +-
 SP/code/botlib/l_struct.c    | 2 +-
 16 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/MP/code/botlib/be_aas_main.c b/MP/code/botlib/be_aas_main.c
index 3683dd3..833eaf2 100644
--- a/MP/code/botlib/be_aas_main.c
+++ b/MP/code/botlib/be_aas_main.c
@@ -339,7 +339,7 @@ int AAS_LoadFiles( const char *mapname ) {
 	}
 
 	botimport.Print( PRT_MESSAGE, "loaded %s\n", aasfile );
-	strncpy( ( *aasworld ).filename, aasfile, MAX_PATH );
+	Q_strncpyz( ( *aasworld ).filename, aasfile, sizeof( ( *aasworld ).filename ) );
 	return BLERR_NOERROR;
 } //end of the function AAS_LoadFiles
 //===========================================================================
diff --git a/MP/code/botlib/be_ai_chat.c b/MP/code/botlib/be_ai_chat.c
index 33f925e..3511277 100644
--- a/MP/code/botlib/be_ai_chat.c
+++ b/MP/code/botlib/be_ai_chat.c
@@ -354,7 +354,7 @@ void BotQueueConsoleMessage( int chatstate, int type, char *message ) {
 	m->handle = cs->handle;
 	m->time = AAS_Time();
 	m->type = type;
-	strncpy( m->message, message, MAX_MESSAGE_SIZE );
+	Q_strncpyz( m->message, message, MAX_MESSAGE_SIZE );
 	m->next = NULL;
 	if ( cs->lastmessage ) {
 		cs->lastmessage->next = m;
@@ -1468,7 +1468,7 @@ int BotFindMatch( char *str, bot_match_t *match, unsigned long int context ) {
 	int i;
 	bot_matchtemplate_t *ms;
 
-	strncpy( match->string, str, MAX_MESSAGE_SIZE );
+	Q_strncpyz( match->string, str, MAX_MESSAGE_SIZE );
 	//remove any trailing enters
 	while ( strlen( match->string ) &&
 			match->string[strlen( match->string ) - 1] == '\n' )
@@ -2015,7 +2015,7 @@ bot_chat_t *BotLoadInitialChat( char *chatfile, char *chatname ) {
 						StripDoubleQuotes( token.string );
 						if ( pass && ptr ) {
 							chattype = (bot_chattype_t *) ptr;
-							strncpy( chattype->name, token.string, MAX_CHATTYPE_NAME );
+							Q_strncpyz( chattype->name, token.string, MAX_CHATTYPE_NAME );
 							chattype->firstchatmessage = NULL;
 							//add the chat type to the chat
 							chattype->next = chat->types;
@@ -2754,7 +2754,7 @@ void BotSetChatName( int chatstate, char *name ) {
 		return;
 	}
 	memset( cs->name, 0, sizeof( cs->name ) );
-	strncpy( cs->name, name, sizeof( cs->name ) );
+	strncpy( cs->name, name, sizeof( cs->name ) - 1 );
 	cs->name[sizeof( cs->name ) - 1] = '\0';
 } //end of the function BotSetChatName
 //===========================================================================
diff --git a/MP/code/botlib/be_ai_goal.c b/MP/code/botlib/be_ai_goal.c
index b3fa965..b449c7e 100644
--- a/MP/code/botlib/be_ai_goal.c
+++ b/MP/code/botlib/be_ai_goal.c
@@ -278,7 +278,7 @@ itemconfig_t *LoadItemConfig( char *filename ) {
 		LibVarSet( "max_iteminfo", "128" );
 	}
 
-	strncpy( path, filename, MAX_PATH );
+	Q_strncpyz( path, filename, sizeof( path ) );
 	source = LoadSourceFile( path );
 	if ( !source ) {
 		botimport.Print( PRT_ERROR, "counldn't load %s\n", path );
@@ -307,7 +307,7 @@ itemconfig_t *LoadItemConfig( char *filename ) {
 				return NULL;
 			} //end if
 			StripDoubleQuotes( token.string );
-			strncpy( ii->classname, token.string, sizeof( ii->classname ) - 1 );
+			Q_strncpyz( ii->classname, token.string, sizeof( ii->classname ) );
 			if ( !ReadStructure( source, &iteminfo_struct, (char *) ii ) ) {
 				FreeMemory( ic );
 				FreeSource( source );
diff --git a/MP/code/botlib/be_ai_weap.c b/MP/code/botlib/be_ai_weap.c
index 6d54ae0..7a7e386 100644
--- a/MP/code/botlib/be_ai_weap.c
+++ b/MP/code/botlib/be_ai_weap.c
@@ -218,7 +218,7 @@ weaponconfig_t *LoadWeaponConfig( char *filename ) {
 		max_projectileinfo = 32;
 		LibVarSet( "max_projectileinfo", "32" );
 	} //end if
-	strncpy( path, filename, MAX_PATH );
+	Q_strncpyz( path, filename, sizeof( path ) );
 	source = LoadSourceFile( path );
 	if ( !source ) {
 		botimport.Print( PRT_ERROR, "counldn't load %s\n", path );
diff --git a/MP/code/botlib/l_log.c b/MP/code/botlib/l_log.c
index 584c629..c0d63ea 100644
--- a/MP/code/botlib/l_log.c
+++ b/MP/code/botlib/l_log.c
@@ -76,7 +76,7 @@ void Log_AlwaysOpen( char *filename ) {
 		botimport.Print( PRT_ERROR, "can't open the log file %s\n", filename );
 		return;
 	} //end if
-	strncpy( logfile.filename, filename, MAX_LOGFILENAMESIZE );
+	Q_strncpyz( logfile.filename, filename, MAX_LOGFILENAMESIZE );
 	botimport.Print( PRT_MESSAGE, "Opened log %s\n", logfile.filename );
 } //end of the function Log_Create
 //===========================================================================
diff --git a/MP/code/botlib/l_precomp.c b/MP/code/botlib/l_precomp.c
index fc615c0..47b1471 100644
--- a/MP/code/botlib/l_precomp.c
+++ b/MP/code/botlib/l_precomp.c
@@ -1295,7 +1295,7 @@ define_t *PC_DefineFromString( char *string ) {
 	script = LoadScriptMemory( string, strlen( string ), "*extern" );
 	//create a new source
 	memset( &src, 0, sizeof( source_t ) );
-	strncpy( src.filename, "*extern", sizeof( src.filename ) - 1 );
+	Q_strncpyz( src.filename, "*extern", sizeof( src.filename ) );
 	src.scriptstack = script;
 #if DEFINEHASHING
 	src.definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) );
diff --git a/MP/code/botlib/l_script.c b/MP/code/botlib/l_script.c
index 947f986..c64f7dc 100644
--- a/MP/code/botlib/l_script.c
+++ b/MP/code/botlib/l_script.c
@@ -812,7 +812,7 @@ int PS_ReadPunctuation( script_t *script, token_t *token ) {
 		if ( script->script_p + len <= script->end_p ) {
 			//if the script contains the punctuation
 			if ( !strncmp( script->script_p, p, len ) ) {
-				strncpy( token->string, p, MAX_TOKEN );
+				Q_strncpyz( token->string, p, MAX_TOKEN );
 				script->script_p += len;
 				token->type = TT_PUNCTUATION;
 				//sub type is the number of the punctuation
diff --git a/MP/code/botlib/l_struct.c b/MP/code/botlib/l_struct.c
index edd0410..f12176c 100644
--- a/MP/code/botlib/l_struct.c
+++ b/MP/code/botlib/l_struct.c
@@ -223,7 +223,7 @@ int ReadString( source_t *source, fielddef_t *fd, void *p ) {
 	//remove the double quotes
 	StripDoubleQuotes( token.string );
 	//copy the string
-	strncpy( (char *) p, token.string, MAX_STRINGFIELD );
+	strncpy( (char *) p, token.string, MAX_STRINGFIELD - 1 );
 	//make sure the string is closed with a zero
 	( (char *)p )[MAX_STRINGFIELD - 1] = '\0';
 	//
diff --git a/SP/code/botlib/be_aas_main.c b/SP/code/botlib/be_aas_main.c
index 37e4c90..ca6b96b 100644
--- a/SP/code/botlib/be_aas_main.c
+++ b/SP/code/botlib/be_aas_main.c
@@ -339,7 +339,7 @@ int AAS_LoadFiles( const char *mapname ) {
 	}
 
 	botimport.Print( PRT_MESSAGE, "loaded %s\n", aasfile );
-	strncpy( ( *aasworld ).filename, aasfile, MAX_PATH );
+	Q_strncpyz( ( *aasworld ).filename, aasfile, sizeof( ( *aasworld ).filename ) );
 	return BLERR_NOERROR;
 } //end of the function AAS_LoadFiles
 //===========================================================================
diff --git a/SP/code/botlib/be_ai_chat.c b/SP/code/botlib/be_ai_chat.c
index 67f26bb..a573dba 100644
--- a/SP/code/botlib/be_ai_chat.c
+++ b/SP/code/botlib/be_ai_chat.c
@@ -354,7 +354,7 @@ void BotQueueConsoleMessage( int chatstate, int type, char *message ) {
 	m->handle = cs->handle;
 	m->time = AAS_Time();
 	m->type = type;
-	strncpy( m->message, message, MAX_MESSAGE_SIZE );
+	Q_strncpyz( m->message, message, MAX_MESSAGE_SIZE );
 	m->next = NULL;
 	if ( cs->lastmessage ) {
 		cs->lastmessage->next = m;
@@ -1468,7 +1468,7 @@ int BotFindMatch( char *str, bot_match_t *match, unsigned long int context ) {
 	int i;
 	bot_matchtemplate_t *ms;
 
-	strncpy( match->string, str, MAX_MESSAGE_SIZE );
+	Q_strncpyz( match->string, str, MAX_MESSAGE_SIZE );
 	//remove any trailing enters
 	while ( strlen( match->string ) &&
 			match->string[strlen( match->string ) - 1] == '\n' )
@@ -2015,7 +2015,7 @@ bot_chat_t *BotLoadInitialChat( char *chatfile, char *chatname ) {
 						StripDoubleQuotes( token.string );
 						if ( pass && ptr ) {
 							chattype = (bot_chattype_t *) ptr;
-							strncpy( chattype->name, token.string, MAX_CHATTYPE_NAME );
+							Q_strncpyz( chattype->name, token.string, MAX_CHATTYPE_NAME );
 							chattype->firstchatmessage = NULL;
 							//add the chat type to the chat
 							chattype->next = chat->types;
@@ -2754,7 +2754,7 @@ void BotSetChatName( int chatstate, char *name ) {
 		return;
 	}
 	memset( cs->name, 0, sizeof( cs->name ) );
-	strncpy( cs->name, name, sizeof( cs->name ) );
+	strncpy( cs->name, name, sizeof( cs->name ) - 1 );
 	cs->name[sizeof( cs->name ) - 1] = '\0';
 } //end of the function BotSetChatName
 //===========================================================================
diff --git a/SP/code/botlib/be_ai_goal.c b/SP/code/botlib/be_ai_goal.c
index f8cd21d..2bd1e4b 100644
--- a/SP/code/botlib/be_ai_goal.c
+++ b/SP/code/botlib/be_ai_goal.c
@@ -278,7 +278,7 @@ itemconfig_t *LoadItemConfig( char *filename ) {
 		LibVarSet( "max_iteminfo", "128" );
 	}
 
-	strncpy( path, filename, MAX_PATH );
+	Q_strncpyz( path, filename, sizeof( path ) );
 	source = LoadSourceFile( path );
 	if ( !source ) {
 		botimport.Print( PRT_ERROR, "counldn't load %s\n", path );
@@ -307,7 +307,7 @@ itemconfig_t *LoadItemConfig( char *filename ) {
 				return NULL;
 			} //end if
 			StripDoubleQuotes( token.string );
-			strncpy( ii->classname, token.string, sizeof( ii->classname ) - 1 );
+			Q_strncpyz( ii->classname, token.string, sizeof( ii->classname ) );
 			if ( !ReadStructure( source, &iteminfo_struct, (char *) ii ) ) {
 				FreeMemory( ic );
 				FreeSource( source );
diff --git a/SP/code/botlib/be_ai_weap.c b/SP/code/botlib/be_ai_weap.c
index 5dca4ad..de3d08f 100644
--- a/SP/code/botlib/be_ai_weap.c
+++ b/SP/code/botlib/be_ai_weap.c
@@ -218,7 +218,7 @@ weaponconfig_t *LoadWeaponConfig( char *filename ) {
 		max_projectileinfo = 32;
 		LibVarSet( "max_projectileinfo", "32" );
 	} //end if
-	strncpy( path, filename, MAX_PATH );
+	Q_strncpyz( path, filename, sizeof( path ) );
 	source = LoadSourceFile( path );
 	if ( !source ) {
 		botimport.Print( PRT_ERROR, "counldn't load %s\n", path );
diff --git a/SP/code/botlib/l_log.c b/SP/code/botlib/l_log.c
index 077e31a..c319047 100644
--- a/SP/code/botlib/l_log.c
+++ b/SP/code/botlib/l_log.c
@@ -76,7 +76,7 @@ void Log_AlwaysOpen( char *filename ) {
 		botimport.Print( PRT_ERROR, "can't open the log file %s\n", filename );
 		return;
 	} //end if
-	strncpy( logfile.filename, filename, MAX_LOGFILENAMESIZE );
+	Q_strncpyz( logfile.filename, filename, MAX_LOGFILENAMESIZE );
 	botimport.Print( PRT_MESSAGE, "Opened log %s\n", logfile.filename );
 } //end of the function Log_Create
 //===========================================================================
diff --git a/SP/code/botlib/l_precomp.c b/SP/code/botlib/l_precomp.c
index 981adf0..3a5484e 100644
--- a/SP/code/botlib/l_precomp.c
+++ b/SP/code/botlib/l_precomp.c
@@ -1295,7 +1295,7 @@ define_t *PC_DefineFromString( char *string ) {
 	script = LoadScriptMemory( string, strlen( string ), "*extern" );
 	//create a new source
 	memset( &src, 0, sizeof( source_t ) );
-	strncpy( src.filename, "*extern", sizeof( src.filename ) - 1 );
+	Q_strncpyz( src.filename, "*extern", sizeof( src.filename ) );
 	src.scriptstack = script;
 #if DEFINEHASHING
 	src.definehash = GetClearedMemory( DEFINEHASHSIZE * sizeof( define_t * ) );
diff --git a/SP/code/botlib/l_script.c b/SP/code/botlib/l_script.c
index d50b1b5..425db33 100644
--- a/SP/code/botlib/l_script.c
+++ b/SP/code/botlib/l_script.c
@@ -812,7 +812,7 @@ int PS_ReadPunctuation( script_t *script, token_t *token ) {
 		if ( script->script_p + len <= script->end_p ) {
 			//if the script contains the punctuation
 			if ( !strncmp( script->script_p, p, len ) ) {
-				strncpy( token->string, p, MAX_TOKEN );
+				Q_strncpyz( token->string, p, MAX_TOKEN );
 				script->script_p += len;
 				token->type = TT_PUNCTUATION;
 				//sub type is the number of the punctuation
diff --git a/SP/code/botlib/l_struct.c b/SP/code/botlib/l_struct.c
index 3045eb8..29e9cab 100644
--- a/SP/code/botlib/l_struct.c
+++ b/SP/code/botlib/l_struct.c
@@ -223,7 +223,7 @@ int ReadString( source_t *source, fielddef_t *fd, void *p ) {
 	//remove the double quotes
 	StripDoubleQuotes( token.string );
 	//copy the string
-	strncpy( (char *) p, token.string, MAX_STRINGFIELD );
+	strncpy( (char *) p, token.string, MAX_STRINGFIELD - 1 );
 	//make sure the string is closed with a zero
 	( (char *)p )[MAX_STRINGFIELD - 1] = '\0';
 	//

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



More information about the Pkg-games-commits mailing list