git-svn: trunk@3930
Török Edvin authored on 2008/07/10 19:29:29... | ... |
@@ -677,147 +677,6 @@ static void handle_de(yystype *tokens, size_t start, const size_t cnt, const cha |
677 | 677 |
res->pos_end++; /* ) */ |
678 | 678 |
} |
679 | 679 |
|
680 |
-/* --------- this should be in str.c -------------------------------- */ |
|
681 |
-static const int hex_chars[256] = { |
|
682 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
683 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
684 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
685 |
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1, -1,-1,-1,-1, |
|
686 |
- -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
687 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
688 |
- -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
689 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
690 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
691 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
692 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
693 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
694 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
695 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
696 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
697 |
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
|
698 |
-}; |
|
699 |
- |
|
700 |
-static inline int cli_hex2int(const char c) |
|
701 |
-{ |
|
702 |
- return hex_chars[(const unsigned char)c]; |
|
703 |
-} |
|
704 |
- |
|
705 |
-static inline size_t output_utf8(uint16_t u, unsigned char* dst) |
|
706 |
-{ |
|
707 |
- if(!u) { |
|
708 |
- *dst = 0x1; /* don't add \0, add \1 instead */ |
|
709 |
- return 1; |
|
710 |
- } |
|
711 |
- if(u < 0x80) { |
|
712 |
- *dst = u&0xff; |
|
713 |
- return 1; |
|
714 |
- } |
|
715 |
- if(u < 0x800) { |
|
716 |
- *dst++ = 0xc0 | (u>>6); /* 110yyyyy */ |
|
717 |
- *dst = 0x80 | (u & 0x3f); /* 10zzzzzz */ |
|
718 |
- return 2; |
|
719 |
- } |
|
720 |
- /* u < 0x10000 because we only handle utf-16, |
|
721 |
- * values in range 0xd800 - 0xdfff aren't valid, but we don't check for |
|
722 |
- * that*/ |
|
723 |
- *dst++ = 0xe0 | (u>>12); /* 1110xxxx */ |
|
724 |
- *dst++ = 0x80 | ((u>>6)&0x3f); /* 10yyyyyy */ |
|
725 |
- *dst = 0x80 | (u & 0x3f); /* 10zzzzzz */ |
|
726 |
- return 3; |
|
727 |
-} |
|
728 |
- |
|
729 |
-void cli_textbuffer_append_normalize(struct text_buffer *buf, const char *str, size_t len) |
|
730 |
-{ |
|
731 |
- size_t i; |
|
732 |
- for(i=0;i < len;i++) { |
|
733 |
- char c = str[i]; |
|
734 |
- if (c == '\\' && i+1 < len) { |
|
735 |
- i++; |
|
736 |
- switch (str[i]) { |
|
737 |
- case '0': |
|
738 |
- c = 0; |
|
739 |
- break; |
|
740 |
- case 'b': |
|
741 |
- c = 8; |
|
742 |
- break; |
|
743 |
- case 't': |
|
744 |
- c = 9; |
|
745 |
- break; |
|
746 |
- case 'n': |
|
747 |
- c = 10; |
|
748 |
- break; |
|
749 |
- case 'v': |
|
750 |
- c = 11; |
|
751 |
- break; |
|
752 |
- case 'f': |
|
753 |
- c = 12; |
|
754 |
- break; |
|
755 |
- case 'r': |
|
756 |
- c=13; |
|
757 |
- break; |
|
758 |
- case 'x': |
|
759 |
- if(i+2 < len) |
|
760 |
- c = (cli_hex2int(str[i+1])<<4)|cli_hex2int(str[i+2]); |
|
761 |
- i += 2; |
|
762 |
- break; |
|
763 |
- case 'u': |
|
764 |
- if(i+4 < len) { |
|
765 |
- uint16_t u = (cli_hex2int(str[i+1])<<12) | (cli_hex2int(str[i+2])<<8) | |
|
766 |
- (cli_hex2int(str[i+3])<<4) | cli_hex2int(str[i+4]); |
|
767 |
- textbuffer_ensure_capacity(buf, 4); |
|
768 |
- buf->pos += output_utf8(u, (unsigned char*)buf->data); |
|
769 |
- i += 4; |
|
770 |
- continue; |
|
771 |
- } |
|
772 |
- break; |
|
773 |
- default: |
|
774 |
- c = str[i]; |
|
775 |
- break; |
|
776 |
- } |
|
777 |
- } |
|
778 |
- if(!c) c = 1; /* we don't insert \0 */ |
|
779 |
- textbuffer_putc(buf, c); |
|
780 |
- } |
|
781 |
-} |
|
782 |
- |
|
783 |
- |
|
784 |
-char *cli_unescape(const char *str) |
|
785 |
-{ |
|
786 |
- char *R; |
|
787 |
- size_t k, i=0; |
|
788 |
- const size_t len = strlen(str); |
|
789 |
- /* unescaped string is at most as long as original, |
|
790 |
- * it will usually be shorter */ |
|
791 |
- R = cli_malloc(len + 1); |
|
792 |
- if(!R) |
|
793 |
- return NULL; |
|
794 |
- for(k=0;k < len;k++) { |
|
795 |
- unsigned char c = str[k]; |
|
796 |
- if (str[k] == '%') { |
|
797 |
- if(k+5 >= len || str[k+1] != 'u' || !isxdigit(str[k+2]) || !isxdigit(str[k+3]) |
|
798 |
- || !isxdigit(str[k+4]) || !isxdigit(str[k+5])) { |
|
799 |
- if(k+2 < len && isxdigit(str[k+1]) && isxdigit(str[k+2])) { |
|
800 |
- c = (cli_hex2int(str[k+1])<<4) | cli_hex2int(str[k+2]); |
|
801 |
- k += 2; |
|
802 |
- } |
|
803 |
- } else { |
|
804 |
- uint16_t u = (cli_hex2int(str[k+2])<<12) | (cli_hex2int(str[k+3])<<8) | |
|
805 |
- (cli_hex2int(str[k+4])<<4) | cli_hex2int(str[k+5]); |
|
806 |
- i += output_utf8(u, (unsigned char*)&R[i]); |
|
807 |
- k += 5; |
|
808 |
- continue; |
|
809 |
- } |
|
810 |
- } |
|
811 |
- if(!c) c = 1; /* don't add \0 */ |
|
812 |
- R[i++] = c; |
|
813 |
- } |
|
814 |
- R[i++] = '\0'; |
|
815 |
- R = cli_realloc2(R, i); |
|
816 |
- return R; |
|
817 |
-} |
|
818 |
- |
|
819 |
-/* ------------ end of str.c ----------------- */ |
|
820 |
- |
|
821 | 680 |
static int handle_unescape(struct tokens *tokens, size_t start, const size_t cnt) |
822 | 681 |
{ |
823 | 682 |
if(tokens->data[start].type == TOK_StringLiteral) { |
... | ... |
@@ -991,7 +850,6 @@ void cli_js_output(struct parser_state *state, const char *tempdir) |
991 | 991 |
unsigned i; |
992 | 992 |
struct buf buf; |
993 | 993 |
char lastchar = '\0'; |
994 |
- char *name; |
|
995 | 994 |
char filename[1024]; |
996 | 995 |
|
997 | 996 |
snprintf(filename, 1024, "%s/javascript", tempdir); |
... | ... |
@@ -1405,7 +1263,10 @@ static inline int parseString(YYSTYPE *lvalp, yyscan_t scanner, const char q, |
1405 | 1405 |
} |
1406 | 1406 |
break; |
1407 | 1407 |
} while (1); |
1408 |
- len = (end && end > start) ? end - start : scanner->insize - scanner->pos; |
|
1408 |
+ if(end && end > start) |
|
1409 |
+ len = end - start; |
|
1410 |
+ else |
|
1411 |
+ len = scanner->insize - scanner->pos; |
|
1409 | 1412 |
cli_textbuffer_append_normalize(&scanner->buf, start, len); |
1410 | 1413 |
if(end) { |
1411 | 1414 |
/* skip over end quote */ |
... | ... |
@@ -19,23 +19,27 @@ static inline int textbuffer_ensure_capacity(struct text_buffer *txtbuf, size_t |
19 | 19 |
return 0; |
20 | 20 |
} |
21 | 21 |
|
22 |
-static inline void textbuffer_append_len(struct text_buffer *txtbuf, const char *s, size_t len) |
|
22 |
+static inline int textbuffer_append_len(struct text_buffer *txtbuf, const char *s, size_t len) |
|
23 | 23 |
{ |
24 |
- textbuffer_ensure_capacity(txtbuf, len); |
|
24 |
+ if(textbuffer_ensure_capacity(txtbuf, len) == -1) |
|
25 |
+ return -1; |
|
25 | 26 |
memcpy(&txtbuf->data[txtbuf->pos], s, len); |
26 | 27 |
txtbuf->pos += len; |
28 |
+ return 0; |
|
27 | 29 |
} |
28 | 30 |
|
29 | 31 |
|
30 |
-static inline void textbuffer_append(struct text_buffer *txtbuf, const char *s) |
|
32 |
+static inline int textbuffer_append(struct text_buffer *txtbuf, const char *s) |
|
31 | 33 |
{ |
32 | 34 |
size_t len = strlen(s); |
33 |
- textbuffer_append_len(txtbuf, s, len); |
|
35 |
+ return textbuffer_append_len(txtbuf, s, len); |
|
34 | 36 |
} |
35 | 37 |
|
36 |
-static inline void textbuffer_putc(struct text_buffer *txtbuf, const char c) |
|
38 |
+static inline int textbuffer_putc(struct text_buffer *txtbuf, const char c) |
|
37 | 39 |
{ |
38 |
- textbuffer_ensure_capacity(txtbuf, 1); |
|
40 |
+ if(textbuffer_ensure_capacity(txtbuf, 1) == -1) |
|
41 |
+ return -1; |
|
39 | 42 |
txtbuf->data[txtbuf->pos++] = c; |
43 |
+ return 0; |
|
40 | 44 |
} |
41 | 45 |
#endif |
... | ... |
@@ -34,6 +34,7 @@ |
34 | 34 |
#include "others.h" |
35 | 35 |
#include "matcher.h" |
36 | 36 |
#include "cltypes.h" |
37 |
+#include "jsparse/textbuf.h" |
|
37 | 38 |
|
38 | 39 |
static const int hex_chars[256] = { |
39 | 40 |
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, |
... | ... |
@@ -448,3 +449,123 @@ int cli_isnumber(const char *str) |
448 | 448 |
|
449 | 449 |
return 1; |
450 | 450 |
} |
451 |
+ |
|
452 |
+/* encodes the unicode character as utf-8 */ |
|
453 |
+static inline size_t output_utf8(uint16_t u, unsigned char* dst) |
|
454 |
+{ |
|
455 |
+ if(!u) { |
|
456 |
+ *dst = 0x1; /* don't add \0, add \1 instead */ |
|
457 |
+ return 1; |
|
458 |
+ } |
|
459 |
+ if(u < 0x80) { |
|
460 |
+ *dst = u&0xff; |
|
461 |
+ return 1; |
|
462 |
+ } |
|
463 |
+ if(u < 0x800) { |
|
464 |
+ *dst++ = 0xc0 | (u>>6); /* 110yyyyy */ |
|
465 |
+ *dst = 0x80 | (u & 0x3f); /* 10zzzzzz */ |
|
466 |
+ return 2; |
|
467 |
+ } |
|
468 |
+ /* u < 0x10000 because we only handle utf-16, |
|
469 |
+ * values in range 0xd800 - 0xdfff aren't valid, but we don't check for |
|
470 |
+ * that*/ |
|
471 |
+ *dst++ = 0xe0 | (u>>12); /* 1110xxxx */ |
|
472 |
+ *dst++ = 0x80 | ((u>>6)&0x3f); /* 10yyyyyy */ |
|
473 |
+ *dst = 0x80 | (u & 0x3f); /* 10zzzzzz */ |
|
474 |
+ return 3; |
|
475 |
+} |
|
476 |
+ |
|
477 |
+/* javascript-like unescape() function */ |
|
478 |
+char *cli_unescape(const char *str) |
|
479 |
+{ |
|
480 |
+ char *R; |
|
481 |
+ size_t k, i=0; |
|
482 |
+ const size_t len = strlen(str); |
|
483 |
+ /* unescaped string is at most as long as original, |
|
484 |
+ * it will usually be shorter */ |
|
485 |
+ R = cli_malloc(len + 1); |
|
486 |
+ if(!R) |
|
487 |
+ return NULL; |
|
488 |
+ for(k=0;k < len;k++) { |
|
489 |
+ unsigned char c = str[k]; |
|
490 |
+ if (str[k] == '%') { |
|
491 |
+ if(k+5 >= len || str[k+1] != 'u' || !isxdigit(str[k+2]) || !isxdigit(str[k+3]) |
|
492 |
+ || !isxdigit(str[k+4]) || !isxdigit(str[k+5])) { |
|
493 |
+ if(k+2 < len && isxdigit(str[k+1]) && isxdigit(str[k+2])) { |
|
494 |
+ c = (cli_hex2int(str[k+1])<<4) | cli_hex2int(str[k+2]); |
|
495 |
+ k += 2; |
|
496 |
+ } |
|
497 |
+ } else { |
|
498 |
+ uint16_t u = (cli_hex2int(str[k+2])<<12) | (cli_hex2int(str[k+3])<<8) | |
|
499 |
+ (cli_hex2int(str[k+4])<<4) | cli_hex2int(str[k+5]); |
|
500 |
+ i += output_utf8(u, (unsigned char*)&R[i]); |
|
501 |
+ k += 5; |
|
502 |
+ continue; |
|
503 |
+ } |
|
504 |
+ } |
|
505 |
+ if(!c) c = 1; /* don't add \0 */ |
|
506 |
+ R[i++] = c; |
|
507 |
+ } |
|
508 |
+ R[i++] = '\0'; |
|
509 |
+ R = cli_realloc2(R, i); |
|
510 |
+ return R; |
|
511 |
+} |
|
512 |
+ |
|
513 |
+/* handle javascript's escape sequences inside strings */ |
|
514 |
+int cli_textbuffer_append_normalize(struct text_buffer *buf, const char *str, size_t len) |
|
515 |
+{ |
|
516 |
+ size_t i; |
|
517 |
+ for(i=0;i < len;i++) { |
|
518 |
+ char c = str[i]; |
|
519 |
+ if (c == '\\' && i+1 < len) { |
|
520 |
+ i++; |
|
521 |
+ switch (str[i]) { |
|
522 |
+ case '0': |
|
523 |
+ c = 0; |
|
524 |
+ break; |
|
525 |
+ case 'b': |
|
526 |
+ c = 8; |
|
527 |
+ break; |
|
528 |
+ case 't': |
|
529 |
+ c = 9; |
|
530 |
+ break; |
|
531 |
+ case 'n': |
|
532 |
+ c = 10; |
|
533 |
+ break; |
|
534 |
+ case 'v': |
|
535 |
+ c = 11; |
|
536 |
+ break; |
|
537 |
+ case 'f': |
|
538 |
+ c = 12; |
|
539 |
+ break; |
|
540 |
+ case 'r': |
|
541 |
+ c=13; |
|
542 |
+ break; |
|
543 |
+ case 'x': |
|
544 |
+ if(i+2 < len) |
|
545 |
+ c = (cli_hex2int(str[i+1])<<4)|cli_hex2int(str[i+2]); |
|
546 |
+ i += 2; |
|
547 |
+ break; |
|
548 |
+ case 'u': |
|
549 |
+ if(i+4 < len) { |
|
550 |
+ uint16_t u = (cli_hex2int(str[i+1])<<12) | (cli_hex2int(str[i+2])<<8) | |
|
551 |
+ (cli_hex2int(str[i+3])<<4) | cli_hex2int(str[i+4]); |
|
552 |
+ if(textbuffer_ensure_capacity(buf, 4) == -1) |
|
553 |
+ return -1; |
|
554 |
+ buf->pos += output_utf8(u, (unsigned char*)&buf->data[buf->pos]); |
|
555 |
+ i += 4; |
|
556 |
+ continue; |
|
557 |
+ } |
|
558 |
+ break; |
|
559 |
+ default: |
|
560 |
+ c = str[i]; |
|
561 |
+ break; |
|
562 |
+ } |
|
563 |
+ } |
|
564 |
+ if(!c) c = 1; /* we don't insert \0 */ |
|
565 |
+ if(textbuffer_putc(buf, c) == -1) |
|
566 |
+ return -1; |
|
567 |
+ } |
|
568 |
+ return 0; |
|
569 |
+} |
|
570 |
+ |
... | ... |
@@ -44,4 +44,8 @@ const char *cli_memstr(const char *haystack, int hs, const char *needle, int ns) |
44 | 44 |
char *cli_strrcpy(char *dest, const char *source); |
45 | 45 |
void cli_strtokenize(char *buffer, const char delim, const size_t token_count, const char **tokens); |
46 | 46 |
int cli_isnumber(const char *str); |
47 |
+char *cli_unescape(const char *str); |
|
48 |
+struct text_buffer; |
|
49 |
+int cli_textbuffer_append_normalize(struct text_buffer *buf, const char *str, size_t len); |
|
50 |
+ |
|
47 | 51 |
#endif |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
TESTS = check_clamav |
2 | 2 |
bin_PROGRAMS = check_clamav |
3 |
-check_clamav_SOURCES = check_clamav.c check_jsnorm.c $(top_builddir)/libclamav/clamav.h |
|
3 |
+check_clamav_SOURCES = check_clamav.c check_jsnorm.c check_str.c $(top_builddir)/libclamav/clamav.h |
|
4 | 4 |
check_clamav_CFLAGS = |
5 | 5 |
check_clamav_LDADD = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @LCHECK@ |
... | ... |
@@ -50,7 +50,8 @@ am__installdirs = "$(DESTDIR)$(bindir)" |
50 | 50 |
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) |
51 | 51 |
PROGRAMS = $(bin_PROGRAMS) |
52 | 52 |
am_check_clamav_OBJECTS = check_clamav-check_clamav.$(OBJEXT) \ |
53 |
- check_clamav-check_jsnorm.$(OBJEXT) |
|
53 |
+ check_clamav-check_jsnorm.$(OBJEXT) \ |
|
54 |
+ check_clamav-check_str.$(OBJEXT) |
|
54 | 55 |
check_clamav_OBJECTS = $(am_check_clamav_OBJECTS) |
55 | 56 |
check_clamav_DEPENDENCIES = $(top_builddir)/libclamav/libclamav.la |
56 | 57 |
check_clamav_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ |
... | ... |
@@ -201,7 +202,7 @@ target_os = @target_os@ |
201 | 201 |
target_vendor = @target_vendor@ |
202 | 202 |
top_builddir = @top_builddir@ |
203 | 203 |
top_srcdir = @top_srcdir@ |
204 |
-check_clamav_SOURCES = check_clamav.c check_jsnorm.c $(top_builddir)/libclamav/clamav.h |
|
204 |
+check_clamav_SOURCES = check_clamav.c check_jsnorm.c check_str.c $(top_builddir)/libclamav/clamav.h |
|
205 | 205 |
check_clamav_CFLAGS = |
206 | 206 |
check_clamav_LDADD = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @LCHECK@ |
207 | 207 |
all: all-am |
... | ... |
@@ -277,6 +278,7 @@ distclean-compile: |
277 | 277 |
|
278 | 278 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_clamav.Po@am__quote@ |
279 | 279 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_jsnorm.Po@am__quote@ |
280 |
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_str.Po@am__quote@ |
|
280 | 281 |
|
281 | 282 |
.c.o: |
282 | 283 |
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< |
... | ... |
@@ -327,6 +329,20 @@ check_clamav-check_jsnorm.obj: check_jsnorm.c |
327 | 327 |
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
328 | 328 |
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -c -o check_clamav-check_jsnorm.obj `if test -f 'check_jsnorm.c'; then $(CYGPATH_W) 'check_jsnorm.c'; else $(CYGPATH_W) '$(srcdir)/check_jsnorm.c'; fi` |
329 | 329 |
|
330 |
+check_clamav-check_str.o: check_str.c |
|
331 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -MT check_clamav-check_str.o -MD -MP -MF $(DEPDIR)/check_clamav-check_str.Tpo -c -o check_clamav-check_str.o `test -f 'check_str.c' || echo '$(srcdir)/'`check_str.c |
|
332 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/check_clamav-check_str.Tpo $(DEPDIR)/check_clamav-check_str.Po |
|
333 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='check_str.c' object='check_clamav-check_str.o' libtool=no @AMDEPBACKSLASH@ |
|
334 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
335 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -c -o check_clamav-check_str.o `test -f 'check_str.c' || echo '$(srcdir)/'`check_str.c |
|
336 |
+ |
|
337 |
+check_clamav-check_str.obj: check_str.c |
|
338 |
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -MT check_clamav-check_str.obj -MD -MP -MF $(DEPDIR)/check_clamav-check_str.Tpo -c -o check_clamav-check_str.obj `if test -f 'check_str.c'; then $(CYGPATH_W) 'check_str.c'; else $(CYGPATH_W) '$(srcdir)/check_str.c'; fi` |
|
339 |
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/check_clamav-check_str.Tpo $(DEPDIR)/check_clamav-check_str.Po |
|
340 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='check_str.c' object='check_clamav-check_str.obj' libtool=no @AMDEPBACKSLASH@ |
|
341 |
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
342 |
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -c -o check_clamav-check_str.obj `if test -f 'check_str.c'; then $(CYGPATH_W) 'check_str.c'; else $(CYGPATH_W) '$(srcdir)/check_str.c'; fi` |
|
343 |
+ |
|
330 | 344 |
mostlyclean-libtool: |
331 | 345 |
-rm -f *.lo |
332 | 346 |
|
... | ... |
@@ -301,6 +301,7 @@ int main(int argc, char **argv) |
301 | 301 |
SRunner *sr = srunner_create(s); |
302 | 302 |
srunner_add_suite(sr, test_cli_suite()); |
303 | 303 |
srunner_add_suite(sr, test_jsnorm_suite()); |
304 |
+ srunner_add_suite(sr, test_str_suite()); |
|
304 | 305 |
|
305 | 306 |
srunner_set_log(sr, "test.log"); |
306 | 307 |
srunner_run_all(sr, CK_NORMAL); |
... | ... |
@@ -150,104 +150,12 @@ START_TEST (test_init_parse_destroy) |
150 | 150 |
} |
151 | 151 |
END_TEST |
152 | 152 |
|
153 |
-static struct text_buffer buf; |
|
154 |
- |
|
155 |
-static void buf_setup(void) |
|
156 |
-{ |
|
157 |
- memset(&buf, 0, sizeof(buf)); |
|
158 |
-} |
|
159 |
- |
|
160 |
-static void buf_teardown(void) |
|
161 |
-{ |
|
162 |
- if(buf.data) |
|
163 |
- free(buf.data); |
|
164 |
- memset(&buf, 0, sizeof(buf)); |
|
165 |
-} |
|
166 |
- |
|
167 |
-START_TEST (test_append_len) |
|
168 |
-{ |
|
169 |
- textbuffer_append_len(&buf, "test",3); |
|
170 |
- fail_unless(buf.data && !strncmp(buf.data,"tes",3), "textbuffer_append_len"); |
|
171 |
-} |
|
172 |
-END_TEST |
|
173 |
- |
|
174 |
-START_TEST (test_append) |
|
175 |
-{ |
|
176 |
- textbuffer_append(&buf, "test"); |
|
177 |
- textbuffer_putc(&buf, '\0'); |
|
178 |
- fail_unless(buf.data && !strcmp(buf.data,"test"), "textbuffer_append"); |
|
179 |
-} |
|
180 |
-END_TEST |
|
181 |
- |
|
182 |
-START_TEST (test_putc) |
|
183 |
-{ |
|
184 |
- textbuffer_putc(&buf, '\x5a'); |
|
185 |
- fail_unless(buf.data && buf.data[0] == '\x5a', "textbuffer_putc"); |
|
186 |
-} |
|
187 |
-END_TEST |
|
188 |
- |
|
189 |
-START_TEST (test_unescape_simple) |
|
190 |
-{ |
|
191 |
- char *str = cli_unescape(""); |
|
192 |
- fail_unless(str && strlen(str) == 0, "cli_unescape empty string"); |
|
193 |
- free(str); |
|
194 |
- |
|
195 |
- str = cli_unescape("1"); |
|
196 |
- fail_unless(str && !strcmp(str,"1"), "cli_unescape one char"); |
|
197 |
- free(str); |
|
198 |
- |
|
199 |
- str = cli_unescape("tesT"); |
|
200 |
- fail_unless(str && !strcmp(str,"tesT"), "cli_unescape simple string"); |
|
201 |
- free(str); |
|
202 |
-} |
|
203 |
-END_TEST |
|
204 |
- |
|
205 |
-START_TEST (test_unescape_hex) |
|
206 |
-{ |
|
207 |
- char *str = cli_unescape("%5a"); |
|
208 |
- fail_unless(str && !strcmp(str,"\x5a"), "cli_unescape hex"); |
|
209 |
- free(str); |
|
210 |
- |
|
211 |
- str = cli_unescape("%b5%8"); |
|
212 |
- fail_unless(str && !strcmp(str,"\xb5%8"), "cli_unescape truncated"); |
|
213 |
- free(str); |
|
214 |
- |
|
215 |
- str = cli_unescape("%b5%"); |
|
216 |
- fail_unless(str && !strcmp(str,"\xb5%"), "cli_unescape truncated/2"); |
|
217 |
- free(str); |
|
218 |
- |
|
219 |
- str = cli_unescape("%00"); |
|
220 |
- fail_unless(str && !strcmp(str,"\x1"), "cli_unescape %00"); |
|
221 |
- free(str); |
|
222 |
-} |
|
223 |
-END_TEST |
|
224 |
- |
|
225 |
-START_TEST (test_unescape_unicode) |
|
226 |
-{ |
|
227 |
- char *str = cli_unescape("%u05D0"); |
|
228 |
- /* unicode is converted to utf-8 representation */ |
|
229 |
- fail_unless(str && !strcmp(str,"\xd7\x90"), "cli_unescape unicode aleph"); |
|
230 |
- free(str); |
|
231 |
- |
|
232 |
- str = cli_unescape("%u00a2%u007f%u0080%u07ff%u0800%ue000"); |
|
233 |
- fail_unless(str && !strcmp(str,"\xc2\xa2\x7f\xc2\x80\xdf\xbf\xe0\xa0\x80\xee\x80\x80"), |
|
234 |
- "cli_unescape utf-8 test"); |
|
235 |
- free(str); |
|
236 |
- |
|
237 |
- str = cli_unescape("%%u123%u12%u1%u%u1234"); |
|
238 |
- fail_unless(str && !strcmp(str,"%%u123%u12%u1%u\xe1\x88\xb4"), |
|
239 |
- "cli_unescape unicode truncated"); |
|
240 |
- |
|
241 |
- free(str); |
|
242 |
-} |
|
243 |
-END_TEST |
|
244 | 153 |
|
245 | 154 |
Suite *test_jsnorm_suite(void); |
246 | 155 |
Suite *test_jsnorm_suite(void) |
247 | 156 |
{ |
248 | 157 |
Suite *s = suite_create("jsnorm"); |
249 |
- TCase *tc_jsnorm_gperf, *tc_jsnorm_token, *tc_jsnorm_api, *tc_jsnorm_tbuf, *tc_cli_unescape, *tc_cli_textbuffer_append_normalize; |
|
250 |
- |
|
158 |
+ TCase *tc_jsnorm_gperf, *tc_jsnorm_token, *tc_jsnorm_api; |
|
251 | 159 |
tc_jsnorm_gperf = tcase_create("jsnorm gperf"); |
252 | 160 |
suite_add_tcase (s, tc_jsnorm_gperf); |
253 | 161 |
tcase_add_loop_test(tc_jsnorm_gperf, test_keywords, 0, sizeof(kw_test)/sizeof(kw_test[0])); |
... | ... |
@@ -266,23 +174,6 @@ Suite *test_jsnorm_suite(void) |
266 | 266 |
tcase_add_test(tc_jsnorm_api, test_init_destroy); |
267 | 267 |
tcase_add_test(tc_jsnorm_api, test_init_parse_destroy); |
268 | 268 |
|
269 |
- tc_jsnorm_tbuf = tcase_create("jsnorm textbuf functions"); |
|
270 |
- suite_add_tcase (s, tc_jsnorm_tbuf); |
|
271 |
- tcase_add_checked_fixture (tc_jsnorm_tbuf, buf_setup, buf_teardown); |
|
272 |
- tcase_add_test(tc_jsnorm_tbuf, test_append_len); |
|
273 |
- tcase_add_test(tc_jsnorm_tbuf, test_append); |
|
274 |
- tcase_add_test(tc_jsnorm_tbuf, test_putc); |
|
275 |
- |
|
276 |
- tc_cli_unescape = tcase_create("cli_unescape"); |
|
277 |
- suite_add_tcase (s, tc_cli_unescape); |
|
278 |
- tcase_add_test(tc_cli_unescape, test_unescape_simple); |
|
279 |
- tcase_add_test(tc_cli_unescape, test_unescape_unicode); |
|
280 |
- tcase_add_test(tc_cli_unescape, test_unescape_hex); |
|
281 |
- |
|
282 |
- |
|
283 |
- tc_cli_textbuffer_append_normalize = tcase_create("cli_textbuffer_append_normalize"); |
|
284 |
- suite_add_tcase (s, tc_cli_textbuffer_append_normalize); |
|
285 |
- |
|
286 | 269 |
return s; |
287 | 270 |
} |
288 | 271 |
|