@@ -210,14 +210,14 @@ static const char *getCurrentTickString(void)
210210 Empty the buffer passed in, then optionally prepend the current TickCount
211211 value in string form, depending on the setting of theDebugFlags.
212212*/
213- static void prepBuffer (char *buffer)
213+ static void prepBuffer (char *buffer, int size )
214214{
215215 buffer[0 ] = 0 ;
216216#ifdef ALLOW_DEBUG_UTILS
217217 if (theDebugFlags & DEBUG_FLAG_PREPEND_TIME)
218218 {
219219 strcpy (buffer, getCurrentTickString ());
220- strcat (buffer, " " );
220+ strlcat (buffer, " " , size );
221221 }
222222#endif
223223}
@@ -388,24 +388,24 @@ void DebugInit(int flags)
388388 }
389389
390390 strcpy (theLogFileNamePrev, dirbuf);
391- strcat (theLogFileNamePrev, gAppPrefix );
392- strcat (theLogFileNamePrev, DEBUG_FILE_NAME_PREV);
391+ strlcat (theLogFileNamePrev, gAppPrefix , ARRAY_SIZE (theLogFileNamePrev) );
392+ strlcat (theLogFileNamePrev, DEBUG_FILE_NAME_PREV, ARRAY_SIZE (theLogFileNamePrev) );
393393 if (rts::ClientInstance::getInstanceId () > 1u )
394394 {
395395 size_t offset = strlen (theLogFileNamePrev);
396396 snprintf (theLogFileNamePrev + offset, ARRAY_SIZE (theLogFileNamePrev) - offset, " _Instance%.2u" , rts::ClientInstance::getInstanceId ());
397397 }
398- strcat (theLogFileNamePrev, " .txt" );
398+ strlcat (theLogFileNamePrev, " .txt" , ARRAY_SIZE (theLogFileNamePrev) );
399399
400400 strcpy (theLogFileName, dirbuf);
401- strcat (theLogFileName, gAppPrefix );
402- strcat (theLogFileName, DEBUG_FILE_NAME);
401+ strlcat (theLogFileName, gAppPrefix , ARRAY_SIZE (theLogFileNamePrev) );
402+ strlcat (theLogFileName, DEBUG_FILE_NAME, ARRAY_SIZE (theLogFileNamePrev) );
403403 if (rts::ClientInstance::getInstanceId () > 1u )
404404 {
405405 size_t offset = strlen (theLogFileName);
406406 snprintf (theLogFileName + offset, ARRAY_SIZE (theLogFileName) - offset, " _Instance%.2u" , rts::ClientInstance::getInstanceId ());
407407 }
408- strcat (theLogFileName, " .txt" );
408+ strlcat (theLogFileName, " .txt" , ARRAY_SIZE (theLogFileNamePrev) );
409409
410410 remove (theLogFileNamePrev);
411411 rename (theLogFileName, theLogFileNamePrev);
@@ -436,7 +436,7 @@ void DebugLog(const char *format, ...)
436436 if (theDebugFlags == 0 )
437437 MessageBoxWrapper (" DebugLog - Debug not inited properly" , " " , MB_OK|MB_TASKMODAL);
438438
439- prepBuffer (theBuffer);
439+ prepBuffer (theBuffer, ARRAY_SIZE (theBuffer) );
440440
441441 va_list args;
442442 va_start (args, format);
@@ -508,8 +508,8 @@ void DebugCrash(const char *format, ...)
508508 // make it big to avoid weird overflow bugs in debug mode
509509 char theCrashBuffer[ LARGE_BUFFER ];
510510
511- prepBuffer (theCrashBuffer);
512- strcat (theCrashBuffer, " ASSERTION FAILURE: " );
511+ prepBuffer (theCrashBuffer, LARGE_BUFFER );
512+ strlcat (theCrashBuffer, " ASSERTION FAILURE: " , LARGE_BUFFER );
513513
514514 va_list arg;
515515 va_start (arg, format);
@@ -538,7 +538,7 @@ void DebugCrash(const char *format, ...)
538538#endif
539539 }
540540
541- strcat (theCrashBuffer, " \n\n Abort->exception; Retry->debugger; Ignore->continue" );
541+ strlcat (theCrashBuffer, " \n\n Abort->exception; Retry->debugger; Ignore->continue" , LARGE_BUFFER );
542542
543543 const int result = doCrashBox (theCrashBuffer, useLogging);
544544
@@ -737,9 +737,9 @@ void ReleaseCrash(const char *reason)
737737 }
738738
739739 strcpy (prevbuf, TheGlobalData->getPath_UserData ().str ());
740- strcat (prevbuf, RELEASECRASH_FILE_NAME_PREV);
740+ strlcat (prevbuf, RELEASECRASH_FILE_NAME_PREV, _MAX_PATH );
741741 strcpy (curbuf, TheGlobalData->getPath_UserData ().str ());
742- strcat (curbuf, RELEASECRASH_FILE_NAME);
742+ strlcat (curbuf, RELEASECRASH_FILE_NAME, _MAX_PATH );
743743
744744 remove (prevbuf);
745745 rename (curbuf, prevbuf);
@@ -826,9 +826,9 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m)
826826 char curbuf[ _MAX_PATH ];
827827
828828 strcpy (prevbuf, TheGlobalData->getPath_UserData ().str ());
829- strcat (prevbuf, RELEASECRASH_FILE_NAME_PREV);
829+ strlcat (prevbuf, RELEASECRASH_FILE_NAME_PREV, _MAX_PATH );
830830 strcpy (curbuf, TheGlobalData->getPath_UserData ().str ());
831- strcat (curbuf, RELEASECRASH_FILE_NAME);
831+ strlcat (curbuf, RELEASECRASH_FILE_NAME, _MAX_PATH );
832832
833833 remove (prevbuf);
834834 rename (curbuf, prevbuf);
0 commit comments