Browse code

Don't add a main() function

git-svn: trunk@2358

Nigel Horne authored on 2006/10/09 19:19:59
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Oct  9 11:19:20 BST 2006 (njh)
2
+----------------------------------
3
+  * libclamav/js.c:	Don't create a main() function
4
+
1 5
 Mon Oct  9 10:09:27 BST 2006 (njh)
2 6
 ----------------------------------
3 7
   * libclamav/js.c:	Was trying to delete the script file even when it
... ...
@@ -19,7 +19,7 @@
19 19
  * Save the JavaScript embedded in an HTML file, then run the script, saving
20 20
  * the output in a file that is to be scanned, then remove the script file
21 21
  */
22
-static	char	const	rcsid[] = "$Id: js.c,v 1.7 2006/10/09 09:22:11 njh Exp $";
22
+static	char	const	rcsid[] = "$Id: js.c,v 1.8 2006/10/09 10:18:43 njh Exp $";
23 23
 
24 24
 #if HAVE_CONFIG_H
25 25
 #include "clamav-config.h"
... ...
@@ -188,13 +188,20 @@ cli_scanjs(const char *dir, int desc)
188 188
 					munmap(buf, size);
189 189
 					return CL_ETMPFILE;
190 190
 				}
191
-				/*
192
-				 * FIXME: the script file could already contain
193
-				 *	main()
194
-				 */
195
-				fputs("function main()\n{\n", fout);
196 191
 				cli_dbgmsg("Saving javascript to %s\n",
197 192
 					script_filename);
193
+
194
+				/*
195
+				 * Create a document object, on web pages it's
196
+				 *	used to send output to the browser
197
+				 */
198
+				fputs("function createDoc() {\n", fout);
199
+				fputs("\tfunction write(text) {\n", fout);
200
+				fputs("\t\tprint(text);\n", fout);
201
+				fputs("\t}\n", fout);
202
+				fputs("}\n", fout);
203
+				fputs("document = new createDoc();\n", fout);
204
+
198 205
 				done_header = 1;
199 206
 			}
200 207
 			putc(c, fout);
... ...
@@ -211,7 +218,6 @@ cli_scanjs(const char *dir, int desc)
211 211
 		extern short cli_leavetemps_flag;
212 212
 		JSInterpPtr interp;
213 213
 
214
-		fputs("\n}\nmain();\n", fout);
215 214
 		fclose(fout);
216 215
 
217 216
 		/*