From 883557c87d730ac5db6f7e33ee3c6d78fdc7f9c2 Mon Sep 17 00:00:00 2001 From: Sergeant_Kolja Date: Tue, 17 Jul 2007 20:18:02 +0000 Subject: [PATCH] fixed an issue in Fileprintf() with too short buffer for vsprintf. switched to more secure version vsnprintf() (that is, in fact avail since VS6 but not as secure as vsprintf_s()). Also inflated the buffer to fit the messages from XML-Writer code (is executed in debug mode only). The inflation has nothing to do with the securing, its only for comfort of the XML writers log messages. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1071 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Standard Gaming Platform/FileMan.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index 7f1e764a..4c62d889 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -777,9 +777,15 @@ BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiB // 9 Feb 98 DEF - modified to work with the library system // //************************************************************************** + +#ifndef DIM +# define DIM(x) (sizeof(x)/sizeof(x[0])) /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */ +#endif + + BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... ) { - CHAR8 strToSend[80]; + CHAR8 strToSend[160]; /* itemdescription of item 0 will NOT fit if only 80 Chars per Line!, Sergeant_Kolja, 2007-06-10 */ va_list argptr; BOOLEAN fRetVal = FALSE; @@ -792,7 +798,8 @@ BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... ) if( sLibraryID == REAL_FILE_LIBRARY_ID ) { va_start(argptr, strFormatted); - vsprintf( strToSend, strFormatted, argptr ); + _vsnprintf( strToSend, DIM(strToSend), strFormatted, argptr ); /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */ + strToSend[ DIM(strToSend)-1 ] = 0; va_end(argptr); fRetVal = FileWrite( hFile, strToSend, strlen(strToSend), NULL );