From cca47321024a54bbe632500ecddb0b8f564579e5 Mon Sep 17 00:00:00 2001 From: Philip Kovacs Date: Tue, 29 Nov 2005 17:35:21 +0000 Subject: [PATCH] added tmpstring overrun guards git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@434 7f574dfc-610e-0410-a909-a81674777703 --- src/conky.c | 16 +++++++++++++--- src/conky.h | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/conky.c b/src/conky.c index ae8fc7fc..d97cd72e 100644 --- a/src/conky.c +++ b/src/conky.c @@ -3462,7 +3462,9 @@ static void draw_string(const char *s) printf("%s\n", s); } /* daemon_run(s); the daemon can be called here, but we need to have a buffer in daemon_run() and we need to tell it when everything is ready to be sent */ - strcpy(tmpstring1, s); + memset(tmpstring1,0,TEXT_BUFFER_SIZE); + memset(tmpstring2,0,TEXT_BUFFER_SIZE); + strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1); pos = 0; added = 0; char space[2]; @@ -3483,13 +3485,21 @@ static void draw_string(const char *s) for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) { - tmpstring2[pos + i2] = ' '; + /* + if ( pos + i2 > TEXT_BUFFER_SIZE-1 ) + fprintf(stderr,"buffer overrun detected\n"); + */ + tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */ added++; } pos += i2; } else { if (tmpstring1[i] != 9) { - tmpstring2[pos] = tmpstring1[i]; + /* + if ( pos > TEXT_BUFFER_SIZE-1 ) + fprintf(stderr,"buffer overrun detected\n"); + */ + tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */ pos++; } } diff --git a/src/conky.h b/src/conky.h index 3ab87f37..a5e14925 100644 --- a/src/conky.h +++ b/src/conky.h @@ -55,6 +55,9 @@ fprintf(stderr, "Conky: " s "\n", ##varargs) #define CRIT_ERR(s, varargs...) \ { fprintf(stderr, "Conky: " s "\n", ##varargs); exit(EXIT_FAILURE); } +#define MIN(a,b) (a>b ? b : a) +#define MAX(a,b) (a