Browse code

reduce stack usage of cli_scanscript (bb #819)

git-svn: trunk@3595

Török Edvin authored on 2008/02/08 21:06:24
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Feb  8 13:50:18 EET 2008 (edwin)
2
+------------------------------------
3
+  * reduce stack usage of cli_scanscript (bb #819)
4
+
1 5
 Thu Feb  7 22:30:51 EET 2008 (edwin)
2 6
 ------------------------------------
3 7
   * clamd: (bb #803)
... ...
@@ -1068,14 +1068,14 @@ static int cli_scanhtml(int desc, cli_ctx *ctx)
1068 1068
 static int cli_scanscript(int desc, cli_ctx *ctx)
1069 1069
 {
1070 1070
 	unsigned char buff[FILEBUFF];
1071
-	unsigned char normalized[SCANBUFF];
1071
+	unsigned char* normalized;
1072 1072
 	struct text_norm_state state;
1073 1073
 	struct stat sb;
1074 1074
 	char *tmpname = NULL;
1075 1075
 	int ofd = -1, ret;
1076 1076
 	ssize_t nread;
1077 1077
 
1078
-	cli_dbgmsg("in cli_scantext()\n");
1078
+	cli_dbgmsg("in cli_scanscript()\n");
1079 1079
 
1080 1080
 	if(fstat(desc, &sb) == -1) {
1081 1081
 		cli_errmsg("cli_scanscript: fstat() failed for descriptor %d\n", desc);
... ...
@@ -1097,7 +1097,12 @@ static int cli_scanscript(int desc, cli_ctx *ctx)
1097 1097
 		}
1098 1098
 	}
1099 1099
 
1100
-	text_normalize_init(&state, normalized, sizeof(normalized));
1100
+	if(!(normalized = cli_malloc(SCANBUFF))) {
1101
+		cli_dbgmsg("cli_scanscript: Unable to malloc %u bytes\n", SCANBUFF);
1102
+		return CL_EMEM;
1103
+	}
1104
+
1105
+	text_normalize_init(&state, normalized, SCANBUFF);
1101 1106
 	ret = CL_CLEAN;
1102 1107
 
1103 1108
 	do {
... ...
@@ -1128,6 +1133,7 @@ static int cli_scanscript(int desc, cli_ctx *ctx)
1128 1128
 		free(tmpname);
1129 1129
 		close(ofd);
1130 1130
 	}
1131
+	free(normalized);
1131 1132
 
1132 1133
 	return ret;
1133 1134
 }