From b3766501a63a68aed9a484490d3f12207a307170 Mon Sep 17 00:00:00 2001 From: Ianos Gnatiuc Date: Wed, 2 Nov 2005 02:09:34 +0000 Subject: [PATCH] Avoiding stack overflow - alloca is not freed before end of function --- golded3/gefind.cpp | 15 +-------------- golded3/geline.cpp | 15 +++++++++++++++ golded3/geprot.h | 1 + 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/golded3/gefind.cpp b/golded3/gefind.cpp index d1f7065..81698e7 100644 --- a/golded3/gefind.cpp +++ b/golded3/gefind.cpp @@ -27,10 +27,6 @@ #include #include -#if defined(__USE_ALLOCA__) -#include -#endif - // ------------------------------------------------------------------ @@ -132,16 +128,7 @@ bool FindString(GMsg* msg, const char* prompt, int what) { Latin2Local(msg->re); for (Line *ln = msg->lin; ln; ln = ln->next) - { -#if defined(__USE_ALLOCA__) - char *temp = (char *)alloca(ln->txt.length()+1); -#else - __extension__ char temp[ln->txt.length()+1]; -#endif - strcpy(temp, ln->txt.c_str()); - Latin2Local(temp); - ln->txt = temp; - } + Latin2Local(ln->txt); } // If hit, search again current mail without shortcircuit evaluation diff --git a/golded3/geline.cpp b/golded3/geline.cpp index 94cf499..955735e 100644 --- a/golded3/geline.cpp +++ b/golded3/geline.cpp @@ -1717,6 +1717,21 @@ void Latin2Local(char *str) } +// ------------------------------------------------------------------ + +void Latin2Local(std::string &str) +{ +#if defined(__USE_ALLOCA__) + char *temp = (char *)alloca(str.length()+1); +#else + __extension__ char temp[str.length()+1]; +#endif + strcpy(temp, str.c_str()); + Latin2Local(temp); + str = temp; +} + + // ------------------------------------------------------------------ char* XlatStr(char* dest, const char* src, int level, Chs* chrtbl, int qpencoded, bool i51) { diff --git a/golded3/geprot.h b/golded3/geprot.h index 51e3464..1a4ed63 100644 --- a/golded3/geprot.h +++ b/golded3/geprot.h @@ -181,6 +181,7 @@ Line* LastLine(Line* line); void MakeLineIndex(GMsg* msg, int rmargin, bool getvalue, bool header_recode); void MsgLineReIndex(GMsg* msg, int viewhidden=-1, int viewkludge=-1, int viewquote=-1); void Latin2Local(char *str); +void Latin2Local(std::string &str); char* XlatStr(char* dest, const char* src, int level, Chs* chrtbl, int qpencoded=false, bool i51=false); char* mime_header_decode(char* decoded, const char* encoded, char* charset = NULL); char* strxmimecpy(char* dest, const char* source, int level, int size, bool detect = false);