From 1521b7ad7d3655d9d9881f44b9287c91c05efaba Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Tue, 26 Nov 2019 16:52:04 +0000 Subject: [PATCH] Fix bug #519 Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4296 --- src/debug/debug_gui.cpp | 11 +++++++---- src/gui/sdlmain.cpp | 8 +++++--- src/misc/support.cpp | 7 +++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/debug/debug_gui.cpp b/src/debug/debug_gui.cpp index a9ab9da9..89051449 100644 --- a/src/debug/debug_gui.cpp +++ b/src/debug/debug_gui.cpp @@ -27,6 +27,7 @@ #include #include +#include "cross.h" #include "support.h" #include "regs.h" #include "debug.h" @@ -56,16 +57,18 @@ void DEBUG_ShowMsg(char const* format,...) { char buf[512]; va_list msg; va_start(msg,format); - vsprintf(buf,format,msg); + vsnprintf(buf,sizeof(buf),format,msg); va_end(msg); + buf[sizeof(buf) - 1] = '\0'; + /* Add newline if not present */ - Bitu len=strlen(buf); - if(buf[len-1]!='\n') strcat(buf,"\n"); + size_t len = strlen(buf); + if(buf[len - 1] != '\n' && len + 1 < sizeof(buf) ) strcat(buf,"\n"); if(debuglog) fprintf(debuglog,"%s",buf); - if (logBuffPos!=logBuff.end()) { + if (logBuffPos != logBuff.end()) { logBuffPos=logBuff.end(); DEBUG_RefreshPage(0); // mvwprintw(dbg.win_out,dbg.win_out->_maxy-1, 0, ""); diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 87a45ebf..34ca3f57 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -1716,12 +1716,14 @@ static BOOL WINAPI ConsoleEventHandler(DWORD event) { static bool no_stdout = false; void GFX_ShowMsg(char const* format,...) { char buf[512]; + va_list msg; va_start(msg,format); - vsprintf(buf,format,msg); - strcat(buf,"\n"); + vsnprintf(buf,sizeof(buf),format,msg); va_end(msg); - if(!no_stdout) printf("%s",buf); //Else buf is parsed again. + + buf[sizeof(buf) - 1] = '\0'; + if (!no_stdout) puts(buf); //Else buf is parsed again. (puts adds end of line) } diff --git a/src/misc/support.cpp b/src/misc/support.cpp index 89f7802a..f539e783 100644 --- a/src/misc/support.cpp +++ b/src/misc/support.cpp @@ -29,6 +29,7 @@ #include #include "dosbox.h" +#include "cross.h" #include "debug.h" #include "support.h" #include "video.h" @@ -182,9 +183,11 @@ void E_Exit(const char * format,...) { #endif va_list msg; va_start(msg,format); - vsprintf(buf,format,msg); + vsnprintf(buf,sizeof(buf),format,msg); va_end(msg); - strcat(buf,"\n"); + + buf[sizeof(buf) - 1] = '\0'; + //strcat(buf,"\n"); catcher should handle the end of line.. throw(buf); }