Browse code

handle unfinishes string tokens in JS parser

git-svn: trunk@4247

Török Edvin authored on 2008/10/11 19:27:27
Showing 7 changed files
... ...
@@ -1,3 +1,10 @@
1
+Sat Oct 11 11:16:02 EEST 2008 (edwin)
2
+-------------------------------------
3
+ * Makefile.am, Makefile.in, libclamav/jsparse/js-norm.c,
4
+ unit_tests/Makefile.am, unit_tests/Makefile.in,
5
+ unit_tests/check_jsnorm.c: handle unfinishes string tokens in JS
6
+ parser
7
+
1 8
 Sat Oct 11 13:01:36 EEST 2008 (edwin)
2 9
 -------------------------------------
3 10
  * libclamav/scanners.c: scan javascript with type 7 (and implicitly
... ...
@@ -31,3 +31,5 @@ DISTCLEANFILES = target.h
31 31
 DISTCHECK_CONFIGURE_FLAGS=--enable-milter CFLAGS="-Wno-pointer-sign -Wno-error=attributes -Werror-implicit-function-declaration -Werror -Wextra -Wall -Wbad-function-cast -Wcast-align -Wendif-labels -Wfloat-equal -Wformat=2 -Wmissing-declarations -Wmissing-prototypes -Wno-error=missing-prototypes -Wnested-externs -Wno-error=nested-externs -Wpointer-arith -Wstrict-prototypes -Wno-error=strict-prototypes -Wno-switch -Wno-switch-enum -Wundef -Wwrite-strings -Wstrict-overflow=1 -Winit-self -Wmissing-include-dirs -Wstrict-aliasing -Wdeclaration-after-statement -Waggregate-return -Wmissing-format-attribute -Wno-error=missing-format-attribute -Wpadded -Wno-error=type-limits -Wno-error=unused-value -Wno-error=unused-variable -Wcast-qual -Wno-error=cast-qual -Wno-error=sign-compare -Wshadow -Wno-error=shadow -Wno-error=uninitialized -fdiagnostics-show-option -Wno-unused-parameter -Wpacked -Wno-error=packed -Wno-error=unreachable-code -Winvalid-pch -Wno-error=invalid-pch -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all -Wstack-protector -Wno-error=padded"
32 32
 lcov:
33 33
 	($(MAKE); cd unit_tests; $(MAKE) lcov)
34
+quick-check:
35
+	($(MAKE); cd unit_tests; $(MAKE) quick-check)
... ...
@@ -823,6 +823,8 @@ uninstall-am: uninstall-binSCRIPTS uninstall-pkgconfigDATA
823 823
 
824 824
 lcov:
825 825
 	($(MAKE); cd unit_tests; $(MAKE) lcov)
826
+quick-check:
827
+	($(MAKE); cd unit_tests; $(MAKE) quick-check)
826 828
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
827 829
 # Otherwise a system limit (for SysV at least) may be exceeded.
828 830
 .NOEXPORT:
... ...
@@ -857,7 +857,41 @@ static void run_decoders(struct parser_state *state)
857 857
 
858 858
 void cli_js_parse_done(struct parser_state* state)
859 859
 {
860
+	struct tokens * tokens = &state->tokens;
861
+	size_t par_balance = 0, i;
862
+	char end = '\0';
863
+	YYSTYPE val;
864
+
860 865
 	cli_dbgmsg(MODULE "in cli_js_parse_done()\n");
866
+	/* close unfinished token */
867
+	switch (state->scanner->state) {
868
+		case DoubleQString:
869
+			end = '"';
870
+			break;
871
+		case SingleQString:
872
+			end = '\'';
873
+			break;
874
+	}
875
+	if (end != '\0')
876
+		cli_js_process_buffer(state, &end, 1);
877
+	/* close remaining paranthesis */
878
+	for (i=0;i<tokens->cnt;i++) {
879
+		if (tokens->data[i].type == TOK_PAR_OPEN)
880
+			par_balance++;
881
+		else if (tokens->data[i].type == TOK_PAR_CLOSE && par_balance > 0)
882
+			par_balance--;
883
+	}
884
+	if (par_balance > 0) {
885
+		memset(&val, 0, sizeof(val));
886
+		val.type = TOK_PAR_CLOSE;
887
+		TOKEN_SET(&val, cstring, ")");
888
+		while (par_balance-- > 0) {
889
+			add_token(state, &val);
890
+		}
891
+	}
892
+
893
+	/* we had to close unfinished strings, paranthesis,
894
+	 * so that the folders/decoders can run properly */
861 895
 	run_folders(&state->tokens);
862 896
 	run_decoders(state);
863 897
 
... ...
@@ -35,6 +35,9 @@ check_clamscan.sh: $(top_builddir)/test/clam.exe
35 35
 $(top_builddir)/test/clam.exe:
36 36
 	(cd $(top_builddir)/test && $(MAKE))
37 37
 
38
+quick-check:
39
+	VALGRIND=no LIBEFENCE=no LIBDUMA=no $(MAKE) check
40
+
38 41
 CLEANFILES=lcov.out *.gcno *.gcda *.log $(FILES) test-stderr.log clamscan.log valgrind-*.log duma.log duma2.log clamscan2.log
39 42
 EXTRA_DIST=.split $(srcdir)/*.ref input test-clamd.conf test-freshclam.conf valgrind.supp virusaction-test.sh $(scripts) preload_run.sh
40 43
 if ENABLE_COVERAGE
... ...
@@ -730,6 +730,9 @@ check_clamscan.sh: $(top_builddir)/test/clam.exe
730 730
 
731 731
 $(top_builddir)/test/clam.exe:
732 732
 	(cd $(top_builddir)/test && $(MAKE))
733
+
734
+quick-check:
735
+	VALGRIND=no LIBEFENCE=no LIBDUMA=no $(MAKE) check
733 736
 @ENABLE_COVERAGE_TRUE@lcov: $(LCOV_HTML)
734 737
 @ENABLE_COVERAGE_TRUE@.libs/check_clamav.gcda: $(TESTS)
735 738
 @ENABLE_COVERAGE_TRUE@	$(LCOV_LCOV) $(DIRECTORIES) --zerocounters
... ...
@@ -357,6 +357,11 @@ static const char jstest_buf13[] =
357 357
 static const char jstest_expected13[] =
358 358
 "<script>var n000</script>";
359 359
 
360
+static const char jstest_buf14[] =
361
+"document.write(unescape('test%20test";
362
+
363
+static const char jstest_expected14[] =
364
+"<script>document.write(\"test test\")</script>";
360 365
 
361 366
 static struct {
362 367
 	const char *in;
... ...
@@ -375,7 +380,8 @@ static struct {
375 375
 	{jstest_buf10, jstest_expected10},
376 376
 	{jstest_buf11, jstest_expected11},
377 377
 	{jstest_buf12, jstest_expected12},
378
-	{jstest_buf13, jstest_expected13}
378
+	{jstest_buf13, jstest_expected13},
379
+	{jstest_buf14, jstest_expected14}
379 380
 };
380 381
 
381 382
 #ifdef CHECK_HAVE_LOOPS