From 2a138cc577bcfe0f06296b139d5da5787670f0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edvin?= Date: Fri, 8 Feb 2008 12:06:24 +0000 Subject: [PATCH] reduce stack usage of cli_scanscript (bb #819) git-svn: trunk@3595 --- ChangeLog | 4 ++++ libclamav/scanners.c | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f27e68d42..f0a018ced 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Feb 8 13:50:18 EET 2008 (edwin) +------------------------------------ + * reduce stack usage of cli_scanscript (bb #819) + Thu Feb 7 22:30:51 EET 2008 (edwin) ------------------------------------ * clamd: (bb #803) diff --git a/libclamav/scanners.c b/libclamav/scanners.c index 0c928d440..73f189bcc 100644 --- a/libclamav/scanners.c +++ b/libclamav/scanners.c @@ -1068,14 +1068,14 @@ static int cli_scanhtml(int desc, cli_ctx *ctx) static int cli_scanscript(int desc, cli_ctx *ctx) { unsigned char buff[FILEBUFF]; - unsigned char normalized[SCANBUFF]; + unsigned char* normalized; struct text_norm_state state; struct stat sb; char *tmpname = NULL; int ofd = -1, ret; ssize_t nread; - cli_dbgmsg("in cli_scantext()\n"); + cli_dbgmsg("in cli_scanscript()\n"); if(fstat(desc, &sb) == -1) { cli_errmsg("cli_scanscript: fstat() failed for descriptor %d\n", desc); @@ -1097,7 +1097,12 @@ static int cli_scanscript(int desc, cli_ctx *ctx) } } - text_normalize_init(&state, normalized, sizeof(normalized)); + if(!(normalized = cli_malloc(SCANBUFF))) { + cli_dbgmsg("cli_scanscript: Unable to malloc %u bytes\n", SCANBUFF); + return CL_EMEM; + } + + text_normalize_init(&state, normalized, SCANBUFF); ret = CL_CLEAN; do { @@ -1128,6 +1133,7 @@ static int cli_scanscript(int desc, cli_ctx *ctx) free(tmpname); close(ofd); } + free(normalized); return ret; }