Browse code

properly null-terminate buffer (bb #1223)

git-svn: trunk@4252

Török Edvin authored on 2008/10/11 22:56:29
Showing 6 changed files
... ...
@@ -1,3 +1,10 @@
1
+Fri Oct 10 18:34:04 EEST 2008 (edwin)
2
+-------------------------------------
3
+ * libclamav/htmlnorm.c, libclamav/libclamav.map,
4
+ unit_tests/check_htmlnorm.c, unit_tests/efence_tests.sh,
5
+ unit_tests/input/screnc_test: properly null-terminate buffer (bb
6
+ #1223)
7
+
1 8
 Sat Oct 11 14:37:57 CEST 2008 (tk)
2 9
 ----------------------------------
3 10
   * docs: document bb#1185
... ...
@@ -268,8 +268,8 @@ static unsigned char *cli_readchunk(FILE *stream, m_area_t *m_area, unsigned int
268 268
 					chunk[chunk_len++] = c;
269 269
 				}
270 270
 			}
271
-			chunk[chunk_len] = '\0';
272 271
 		}
272
+		chunk[chunk_len] = '\0';
273 273
 		if(chunk_len == max_len - 1) {
274 274
 			/* rewind to a space (which includes newline) */
275 275
 			count = rewind_tospace(chunk, chunk_len);
... ...
@@ -537,6 +537,8 @@ static void screnc_decode(unsigned char *ptr, struct screnc_state *s)
537 537
 		} else {
538 538
 			*dst++ = *ptr++;
539 539
 			*dst++ = *ptr;
540
+			if (!*ptr)
541
+				break;
540 542
 		}
541 543
 		ptr++;
542 544
 		s->length--;
... ...
@@ -117,6 +117,7 @@ CLAMAV_PRIVATE {
117 117
     cli_bm_init;
118 118
     cli_bm_scanbuff;
119 119
     cli_bm_free;
120
+    html_screnc_decode;
120 121
   local:
121 122
     *;
122 123
 };
... ...
@@ -139,6 +139,17 @@ START_TEST (test_htmlnorm_api)
139 139
 END_TEST
140 140
 #endif
141 141
 
142
+START_TEST(test_screnc_nullterminate)
143
+{
144
+	int fd = open_testfile("input/screnc_test");
145
+
146
+	fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
147
+	fail_unless(html_screnc_decode(fd, dir) == 1, "html_screnc_decode failed");
148
+	fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
149
+	close(fd);
150
+}
151
+END_TEST
152
+
142 153
 Suite *test_htmlnorm_suite(void)
143 154
 {
144 155
 	Suite *s = suite_create("htmlnorm");
... ...
@@ -151,6 +162,7 @@ Suite *test_htmlnorm_suite(void)
151 151
 #endif
152 152
 	tcase_add_unchecked_fixture(tc_htmlnorm_api,
153 153
 					htmlnorm_setup, htmlnorm_teardown);
154
+	tcase_add_test(tc_htmlnorm_api, test_screnc_nullterminate);
154 155
 
155 156
 	return s;
156 157
 }
... ...
@@ -19,7 +19,7 @@ if test ! -n "$VALGRIND" || test ! -x "$VALGRIND"; then
19 19
 	# run check_clamav under efence only if we don't have valgrind installed
20 20
 	echo "--- Running check_clamav under electric-fence"
21 21
 	CK_FORK=no ../libtool --mode=execute $abs_srcdir/preload_run.sh ./check_clamav
22
-	if test ! $?; then
22
+	if test $? -ne 0; then
23 23
 		echo "*** Electric-fence has detected errors"
24 24
 		exit 1
25 25
 	fi
26 26
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+#@~^JyAAAA==@#@&0;	mDkW	P6GWv#~	@#@&7-mDPXxJwsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswsswooswswsosoowsoswoswsoowssoowsoswowsowswsswswoswsoswsoowsswoswJi@#@&58gIAA==^#~@ 
1
+