From 15e481d62d253044f3f7403b4bcbc85910b08084 Mon Sep 17 00:00:00 2001 From: Stas Degteff Date: Thu, 15 Sep 2005 19:29:51 +0000 Subject: [PATCH] Fix buffer overflow when quotemargin>255 --- golded3/getpls.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/golded3/getpls.cpp b/golded3/getpls.cpp index 59bb562..a574be6 100644 --- a/golded3/getpls.cpp +++ b/golded3/getpls.cpp @@ -24,6 +24,10 @@ // Template handling. // ------------------------------------------------------------------ +#if defined(__MINGW32__) || defined(_MSC_VER) +#include +#endif + #if defined(_MSC_VER) && defined(_DEBUG) /* C4786: 'identifier' : identifier was truncated to 'number' characters in the debug information @@ -83,7 +87,12 @@ int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origa uint ctrlinfo; char textfile[GMAXPATH]; char indexfile[GMAXPATH]; - char buf[256]; +#if defined(__MINGW32__) || defined(_MSC_VER) + size_t sizeofbuf = CFG->quotemargin + 256; + char *buf = (char*)alloca(sizeofbuf); +#else + __extension__ char buf[CFG->quotemargin + 256]; +#endif char initials[10]; char quotestr[100]; char qbuf[100]; @@ -317,7 +326,11 @@ int TemplateToText(int mode, GMsg* msg, GMsg* oldmsg, const char* tpl, int origa size_t oldmsg_size = oldmsg->txt ? strlen(oldmsg->txt) : REALLOC_CACHE_SIZE; size_t msg_txt_realloc_cache = 0; +#if defined(__MINGW32__) || defined(_MSC_VER) + while(fgets(buf, sizeofbuf, fp)) { +#else while(fgets(buf, sizeof(buf), fp)) { +#endif ptr = strskip_wht(buf); if(*ptr != ';') { bool chg = false;