Browse code

Preserve the case of href tags. Minor cleanup.

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@868 77e5149b-7576-45b1-b177-96237e5ba77b

Trog authored on 2004/09/15 18:07:45
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Sep 15 10:04:52 BST 2004 (trog)
2
+-----------------------------------
3
+  * libclamav/htmlnorm.c: Preserve the case of href tags. Minor cleanup.
4
+
1 5
 Wed Sep 15 09:47:15 BST 2004 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter:	--help now includes --max-children
... ...
@@ -29,6 +29,7 @@
29 29
 #include <string.h>
30 30
 #include <errno.h>
31 31
 #include <stdio.h>
32
+#include <ctype.h>
32 33
 
33 34
 #if HAVE_CONFIG_H
34 35
 #include "clamav-config.h"
... ...
@@ -50,24 +51,23 @@
50 50
 #define TRUE (1)
51 51
 
52 52
 typedef enum {
53
-    HTML_BAD_STATE=0,
54
-    HTML_NORM=1,
55
-    HTML_COMMENT=2,
56
-    HTML_CHAR_REF=3,
57
-    HTML_JS_DECODE=4,
58
-    HTML_SKIP_WS=5,
59
-    HTML_TRIM_WS=6,
60
-    HTML_TAG=7,
61
-    HTML_TAG_ARG=8,
62
-    HTML_TAG_ARG_VAL=9,
63
-    HTML_TAG_ARG_EQUAL=10,
64
-    HTML_PROCESS_TAG=11,
65
-    HTML_CHAR_REF_DECODE=12,
66
-    HTML_SKIP_LENGTH=13,
67
-    HTML_JSDECODE=14,
68
-    HTML_JSDECODE_LENGTH=15,
69
-    HTML_JSDECODE_DECRYPT=16,
70
-    HTML_SPECIAL_CHAR=17,
53
+    HTML_BAD_STATE,
54
+    HTML_NORM,
55
+    HTML_COMMENT,
56
+    HTML_CHAR_REF,
57
+    HTML_SKIP_WS,
58
+    HTML_TRIM_WS,
59
+    HTML_TAG,
60
+    HTML_TAG_ARG,
61
+    HTML_TAG_ARG_VAL,
62
+    HTML_TAG_ARG_EQUAL,
63
+    HTML_PROCESS_TAG,
64
+    HTML_CHAR_REF_DECODE,
65
+    HTML_SKIP_LENGTH,
66
+    HTML_JSDECODE,
67
+    HTML_JSDECODE_LENGTH,
68
+    HTML_JSDECODE_DECRYPT,
69
+    HTML_SPECIAL_CHAR,
71 70
 } html_state;
72 71
 
73 72
 typedef enum {
... ...
@@ -145,12 +145,10 @@ int decrypt_tables[3][128] = {
145 145
        0x3B, 0x57, 0x22, 0x6D, 0x4D, 0x25, 0x28, 0x46, 0x4A, 0x32, 0x41, 0x3D, 0x5F, 0x4F, 0x42, 0x65}
146 146
 };
147 147
 
148
-/* TODO: mmap support */
149 148
 static unsigned char *cli_readline(FILE *stream, m_area_t *m_area, unsigned int max_len)
150 149
 {
151 150
 	unsigned char *line, *ptr, *start, *end;
152 151
 	unsigned int line_len, count;
153
-	int fddup;
154 152
 
155 153
 	line = (unsigned char *) malloc(max_len);
156 154
 	if (!line) {
... ...
@@ -248,7 +246,7 @@ static void html_output_c(file_buff_t *fbuff1, file_buff_t *fbuff2, unsigned cha
248 248
 	}
249 249
 }
250 250
 
251
-static html_output_str(file_buff_t *fbuff, unsigned char *str, int len)
251
+static void html_output_str(file_buff_t *fbuff, unsigned char *str, int len)
252 252
 {
253 253
 	if (fbuff) {
254 254
 		if ((fbuff->length + len) >= HTML_FILE_BUFF_LEN) {
... ...
@@ -288,9 +286,9 @@ static void html_tag_arg_add(tag_arguments_t *tags,
288 288
 {
289 289
 	int len;
290 290
 	tags->count++;
291
-	tags->tag = (unsigned char **) realloc(tags->tag,
291
+	tags->tag = (unsigned char **) cli_realloc(tags->tag,
292 292
 				tags->count * sizeof(char *));
293
-	tags->value = (unsigned char **) realloc(tags->value,
293
+	tags->value = (unsigned char **) cli_realloc(tags->value,
294 294
 				tags->count * sizeof(char *));
295 295
 	if (!tags->tag || !tags->value) {
296 296
 		tags->count--;
... ...
@@ -314,7 +312,7 @@ static void html_tag_arg_add(tag_arguments_t *tags,
314 314
 
315 315
 static void html_output_tag(file_buff_t *fbuff, char *tag, tag_arguments_t *tags)
316 316
 {
317
-	int i;
317
+	int i, j, len;
318 318
 
319 319
 	html_output_c(fbuff, NULL, '<');
320 320
 	html_output_str(fbuff, tag, strlen(tag));
... ...
@@ -323,7 +321,10 @@ static void html_output_tag(file_buff_t *fbuff, char *tag, tag_arguments_t *tags
323 323
 		html_output_str(fbuff, tags->tag[i], strlen(tags->tag[i]));
324 324
 		if (tags->value[i]) {
325 325
 			html_output_str(fbuff, "=\"", 2);
326
-			html_output_str(fbuff, tags->value[i], strlen(tags->value[i]));
326
+			len = strlen(tags->value[i]);
327
+			for (j=0 ; j<len ; j++) {
328
+				html_output_c(fbuff, NULL, tolower(tags->value[i][j]));
329
+			}
327 330
 			html_output_c(fbuff, NULL, '"');
328 331
 		}
329 332
 	}
... ...
@@ -690,7 +691,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
690 690
 				} else {
691 691
 					html_output_c(file_buff_o1, file_buff_o2, tolower(*ptr));
692 692
 					if (tag_val_length < HTML_STR_LENGTH) {
693
-						tag_val[tag_val_length++] = tolower(*ptr);
693
+						tag_val[tag_val_length++] = *ptr;
694 694
 					}
695 695
 					ptr++;
696 696
 				}
... ...
@@ -903,7 +904,7 @@ int html_normalise_mem(unsigned char *in_buff, off_t in_size, const char *dirnam
903 903
 	m_area.length = in_size;
904 904
 	m_area.offset = 0;
905 905
 	
906
-	cli_html_normalise(-1, &m_area, dirname, hrefs);
906
+	return cli_html_normalise(-1, &m_area, dirname, hrefs);
907 907
 }
908 908
 
909 909
 int html_normalise_fd(int fd, const char *dirname, tag_arguments_t *hrefs)