... | ... |
@@ -29,7 +29,7 @@ |
29 | 29 |
#include <sys/stat.h> |
30 | 30 |
|
31 | 31 |
#include <assert.h> |
32 |
-#ifdef HAVE_UNISTD_H |
|
32 |
+#ifdef HAVE_UNISTD_H |
|
33 | 33 |
#include <unistd.h> |
34 | 34 |
#endif |
35 | 35 |
|
... | ... |
@@ -46,25 +46,25 @@ |
46 | 46 |
|
47 | 47 |
#include "mpool.h" |
48 | 48 |
|
49 |
-#define AC_SPECIAL_ALT_CHAR 1 |
|
50 |
-#define AC_SPECIAL_ALT_STR_FIXED 2 |
|
51 |
-#define AC_SPECIAL_ALT_STR 3 |
|
52 |
-#define AC_SPECIAL_LINE_MARKER 4 |
|
53 |
-#define AC_SPECIAL_BOUNDARY 5 |
|
54 |
-#define AC_SPECIAL_WORD_MARKER 6 |
|
55 |
- |
|
56 |
-#define AC_BOUNDARY_LEFT 0x0001 |
|
57 |
-#define AC_BOUNDARY_LEFT_NEGATIVE 0x0002 |
|
58 |
-#define AC_BOUNDARY_RIGHT 0x0004 |
|
59 |
-#define AC_BOUNDARY_RIGHT_NEGATIVE 0x0008 |
|
60 |
-#define AC_LINE_MARKER_LEFT 0x0010 |
|
61 |
-#define AC_LINE_MARKER_LEFT_NEGATIVE 0x0020 |
|
62 |
-#define AC_LINE_MARKER_RIGHT 0x0040 |
|
63 |
-#define AC_LINE_MARKER_RIGHT_NEGATIVE 0x0080 |
|
64 |
-#define AC_WORD_MARKER_LEFT 0x0100 |
|
65 |
-#define AC_WORD_MARKER_LEFT_NEGATIVE 0x0200 |
|
66 |
-#define AC_WORD_MARKER_RIGHT 0x0400 |
|
67 |
-#define AC_WORD_MARKER_RIGHT_NEGATIVE 0x0800 |
|
49 |
+#define AC_SPECIAL_ALT_CHAR 1 |
|
50 |
+#define AC_SPECIAL_ALT_STR_FIXED 2 |
|
51 |
+#define AC_SPECIAL_ALT_STR 3 |
|
52 |
+#define AC_SPECIAL_LINE_MARKER 4 |
|
53 |
+#define AC_SPECIAL_BOUNDARY 5 |
|
54 |
+#define AC_SPECIAL_WORD_MARKER 6 |
|
55 |
+ |
|
56 |
+#define AC_BOUNDARY_LEFT 0x0001 |
|
57 |
+#define AC_BOUNDARY_LEFT_NEGATIVE 0x0002 |
|
58 |
+#define AC_BOUNDARY_RIGHT 0x0004 |
|
59 |
+#define AC_BOUNDARY_RIGHT_NEGATIVE 0x0008 |
|
60 |
+#define AC_LINE_MARKER_LEFT 0x0010 |
|
61 |
+#define AC_LINE_MARKER_LEFT_NEGATIVE 0x0020 |
|
62 |
+#define AC_LINE_MARKER_RIGHT 0x0040 |
|
63 |
+#define AC_LINE_MARKER_RIGHT_NEGATIVE 0x0080 |
|
64 |
+#define AC_WORD_MARKER_LEFT 0x0100 |
|
65 |
+#define AC_WORD_MARKER_LEFT_NEGATIVE 0x0200 |
|
66 |
+#define AC_WORD_MARKER_RIGHT 0x0400 |
|
67 |
+#define AC_WORD_MARKER_RIGHT_NEGATIVE 0x0800 |
|
68 | 68 |
|
69 | 69 |
static char boundary[256] = { |
70 | 70 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, |
... | ... |
@@ -148,35 +148,35 @@ static inline int insert_list(struct cli_matcher *root, struct cli_ac_patt *patt |
148 | 148 |
break; |
149 | 149 |
} |
150 | 150 |
} else if(a1->type == AC_SPECIAL_ALT_STR_FIXED) { |
151 |
- if(a1->len != a2->len) { |
|
152 |
- match = 0; |
|
153 |
- break; |
|
154 |
- } |
|
155 |
- |
|
156 |
- for(j = 0; j < a1->num; j++) { |
|
157 |
- if(memcmp((a1->alt).f_str[j], (a2->alt).f_str[j], a1->len)) |
|
158 |
- break; |
|
159 |
- } |
|
160 |
- |
|
161 |
- if(j < a1->num) { |
|
162 |
- match = 0; |
|
163 |
- break; |
|
164 |
- } |
|
151 |
+ if(a1->len != a2->len) { |
|
152 |
+ match = 0; |
|
153 |
+ break; |
|
154 |
+ } |
|
155 |
+ |
|
156 |
+ for(j = 0; j < a1->num; j++) { |
|
157 |
+ if(memcmp((a1->alt).f_str[j], (a2->alt).f_str[j], a1->len)) |
|
158 |
+ break; |
|
159 |
+ } |
|
160 |
+ |
|
161 |
+ if(j < a1->num) { |
|
162 |
+ match = 0; |
|
163 |
+ break; |
|
164 |
+ } |
|
165 | 165 |
} else if(a1->type == AC_SPECIAL_ALT_STR) { |
166 |
- b1 = (a1->alt).v_str; |
|
167 |
- b2 = (a2->alt).v_str; |
|
168 |
- while(b1 && b2) { |
|
169 |
- if((b1->len != b2->len) || memcmp(b1->str, b2->str, b1->len)) |
|
170 |
- break; |
|
171 |
- b1 = b1->next; |
|
172 |
- b2 = b2->next; |
|
173 |
- } |
|
174 |
- |
|
175 |
- if(b1 || b2) { |
|
176 |
- match = 0; |
|
177 |
- break; |
|
178 |
- } |
|
179 |
- } |
|
166 |
+ b1 = (a1->alt).v_str; |
|
167 |
+ b2 = (a2->alt).v_str; |
|
168 |
+ while(b1 && b2) { |
|
169 |
+ if((b1->len != b2->len) || memcmp(b1->str, b2->str, b1->len)) |
|
170 |
+ break; |
|
171 |
+ b1 = b1->next; |
|
172 |
+ b2 = b2->next; |
|
173 |
+ } |
|
174 |
+ |
|
175 |
+ if(b1 || b2) { |
|
176 |
+ match = 0; |
|
177 |
+ break; |
|
178 |
+ } |
|
179 |
+ } |
|
180 | 180 |
} |
181 | 181 |
} else { |
182 | 182 |
match = 0; |
... | ... |
@@ -438,7 +438,7 @@ static int ac_maketrans(struct cli_matcher *root) |
438 | 438 |
node = ac_root->trans[i]; |
439 | 439 |
if(node != ac_root) { |
440 | 440 |
if((ret = bfs_enqueue(&bfs, &bfs_last, node))) |
441 |
- return ret; |
|
441 |
+ return ret; |
|
442 | 442 |
} |
443 | 443 |
} |
444 | 444 |
|
... | ... |
@@ -549,22 +549,22 @@ static void ac_free_special(struct cli_ac_patt *p) |
549 | 549 |
|
550 | 550 |
for(i = 0; i < p->special; i++) { |
551 | 551 |
a1 = p->special_table[i]; |
552 |
- if (a1->type == AC_SPECIAL_ALT_CHAR) { |
|
553 |
- mpool_free(mempool, (a1->alt).byte); |
|
554 |
- } else if (a1->type == AC_SPECIAL_ALT_STR_FIXED) { |
|
555 |
- for (j = 0; j < a1->num; j++) |
|
556 |
- mpool_free(mempool, (a1->alt).f_str[j]); |
|
557 |
- mpool_free(mempool, (a1->alt).f_str); |
|
558 |
- } else if (a1->type == AC_SPECIAL_ALT_STR) { |
|
559 |
- b1 = (a1->alt).v_str; |
|
560 |
- while (b1) { |
|
561 |
- b2 = b1->next; |
|
562 |
- mpool_free(mempool, b1->str); |
|
563 |
- mpool_free(mempool, b1); |
|
564 |
- b1 = b2; |
|
565 |
- } |
|
566 |
- } |
|
567 |
- mpool_free(mempool, a1); |
|
552 |
+ if (a1->type == AC_SPECIAL_ALT_CHAR) { |
|
553 |
+ mpool_free(mempool, (a1->alt).byte); |
|
554 |
+ } else if (a1->type == AC_SPECIAL_ALT_STR_FIXED) { |
|
555 |
+ for (j = 0; j < a1->num; j++) |
|
556 |
+ mpool_free(mempool, (a1->alt).f_str[j]); |
|
557 |
+ mpool_free(mempool, (a1->alt).f_str); |
|
558 |
+ } else if (a1->type == AC_SPECIAL_ALT_STR) { |
|
559 |
+ b1 = (a1->alt).v_str; |
|
560 |
+ while (b1) { |
|
561 |
+ b2 = b1->next; |
|
562 |
+ mpool_free(mempool, b1->str); |
|
563 |
+ mpool_free(mempool, b1); |
|
564 |
+ b1 = b2; |
|
565 |
+ } |
|
566 |
+ } |
|
567 |
+ mpool_free(mempool, a1); |
|
568 | 568 |
} |
569 | 569 |
mpool_free(mempool, p->special_table); |
570 | 570 |
} |
... | ... |
@@ -875,48 +875,48 @@ inline static int ac_findmatch_special(const unsigned char *buffer, uint32_t off |
875 | 875 |
switch(special->type) { |
876 | 876 |
case AC_SPECIAL_ALT_CHAR: /* single-byte */ |
877 | 877 |
for (j = 0; j < special->num; j++) { |
878 |
- if ((special->alt).byte[j] == b) { |
|
879 |
- match = !special->negative; |
|
880 |
- break; |
|
881 |
- } else if ((special->alt).byte[j] > b) |
|
882 |
- break; |
|
878 |
+ if ((special->alt).byte[j] == b) { |
|
879 |
+ match = !special->negative; |
|
880 |
+ break; |
|
881 |
+ } else if ((special->alt).byte[j] > b) |
|
882 |
+ break; |
|
883 | 883 |
} |
884 | 884 |
break; |
885 | 885 |
|
886 | 886 |
case AC_SPECIAL_ALT_STR_FIXED: /* fixed length multi-byte */ |
887 |
- if (offset + special->len > length) |
|
888 |
- break; |
|
889 |
- |
|
890 |
- for (j = 0; j < special->num; j++) { |
|
891 |
- if (!memcmp(&buffer[offset], (special->alt).f_str[j], special->len)) { |
|
892 |
- match = (!special->negative) * special->len; |
|
893 |
- break; |
|
894 |
- } /* TODO - handle sorting case */ |
|
895 |
- } |
|
887 |
+ if (offset + special->len > length) |
|
888 |
+ break; |
|
889 |
+ |
|
890 |
+ for (j = 0; j < special->num; j++) { |
|
891 |
+ if (!memcmp(&buffer[offset], (special->alt).f_str[j], special->len)) { |
|
892 |
+ match = (!special->negative) * special->len; |
|
893 |
+ break; |
|
894 |
+ } /* TODO - handle sorting case */ |
|
895 |
+ } |
|
896 | 896 |
break; |
897 | 897 |
|
898 | 898 |
case AC_SPECIAL_ALT_STR: /* generic */ |
899 | 899 |
/* branch for backtracking */ |
900 |
- alt = (special->alt).v_str; |
|
901 |
- while (alt) { |
|
902 |
- if (offset + alt->len > length) { |
|
903 |
- alt = alt->next; |
|
904 |
- continue; |
|
905 |
- } |
|
906 |
- |
|
907 |
- /* note that generic alternates CANNOT be negated */ |
|
908 |
- /* generic alternates are sorted alphabetically */ |
|
909 |
- cmp = memcmp(&buffer[offset], alt->str, alt->len); |
|
910 |
- if (!cmp) { |
|
911 |
- match = ac_findmatch_branch(buffer, offset+alt->len, fileoffset, length, pattern, pattoffset+1, specialcnt+1, end); |
|
912 |
- if (match) |
|
913 |
- return -1; /* alerts caller that match has been resolved in child callee */ |
|
914 |
- } else if (cmp < 0) |
|
915 |
- break; |
|
916 |
- |
|
917 |
- alt = alt->next; |
|
918 |
- } |
|
919 |
- break; |
|
900 |
+ alt = (special->alt).v_str; |
|
901 |
+ while (alt) { |
|
902 |
+ if (offset + alt->len > length) { |
|
903 |
+ alt = alt->next; |
|
904 |
+ continue; |
|
905 |
+ } |
|
906 |
+ |
|
907 |
+ /* note that generic alternates CANNOT be negated */ |
|
908 |
+ /* generic alternates are sorted alphabetically */ |
|
909 |
+ cmp = memcmp(&buffer[offset], alt->str, alt->len); |
|
910 |
+ if (!cmp) { |
|
911 |
+ match = ac_findmatch_branch(buffer, offset+alt->len, fileoffset, length, pattern, pattoffset+1, specialcnt+1, end); |
|
912 |
+ if (match) |
|
913 |
+ return -1; /* alerts caller that match has been resolved in child callee */ |
|
914 |
+ } else if (cmp < 0) |
|
915 |
+ break; |
|
916 |
+ |
|
917 |
+ alt = alt->next; |
|
918 |
+ } |
|
919 |
+ break; |
|
920 | 920 |
|
921 | 921 |
case AC_SPECIAL_LINE_MARKER: |
922 | 922 |
if(b == '\n') |
... | ... |
@@ -944,43 +944,43 @@ inline static int ac_findmatch_special(const unsigned char *buffer, uint32_t off |
944 | 944 |
} |
945 | 945 |
|
946 | 946 |
/* call only by ac_findmatch_branch! */ |
947 |
-#define AC_MATCH_CHAR(p,b) \ |
|
948 |
- switch(wc = p & CLI_MATCH_METADATA) { \ |
|
949 |
- case CLI_MATCH_CHAR: \ |
|
950 |
- if((unsigned char) p != b) \ |
|
951 |
- match = 0; \ |
|
952 |
- break; \ |
|
953 |
- \ |
|
954 |
- case CLI_MATCH_NOCASE: \ |
|
955 |
- if((unsigned char)(p & 0xff) != cli_nocase(b)) \ |
|
956 |
- match = 0; \ |
|
957 |
- break; \ |
|
958 |
- \ |
|
959 |
- case CLI_MATCH_IGNORE: \ |
|
960 |
- break; \ |
|
961 |
- \ |
|
962 |
- case CLI_MATCH_SPECIAL: \ |
|
963 |
- /* >1 = movement, 0 = fail, <1 = resolved in branch */ \ |
|
964 |
- if ((match = ac_findmatch_special(buffer, bp, fileoffset, length, pattern, i, \ |
|
965 |
- specialcnt, end)) <= 0) \ |
|
966 |
- return match; \ |
|
967 |
- bp += match; \ |
|
968 |
- specialcnt++; \ |
|
969 |
- continue; /* match value includes bp++ */ \ |
|
970 |
- \ |
|
971 |
- case CLI_MATCH_NIBBLE_HIGH: \ |
|
972 |
- if((unsigned char) (p & 0x00f0) != (b & 0xf0)) \ |
|
973 |
- match = 0; \ |
|
974 |
- break; \ |
|
975 |
- \ |
|
976 |
- case CLI_MATCH_NIBBLE_LOW: \ |
|
977 |
- if((unsigned char) (p & 0x000f) != (b & 0x0f)) \ |
|
978 |
- match = 0; \ |
|
979 |
- break; \ |
|
980 |
- \ |
|
981 |
- default: \ |
|
982 |
- cli_errmsg("ac_findmatch: Unknown wildcard 0x%x\n", wc); \ |
|
983 |
- match = 0; \ |
|
947 |
+#define AC_MATCH_CHAR(p,b) \ |
|
948 |
+ switch(wc = p & CLI_MATCH_METADATA) { \ |
|
949 |
+ case CLI_MATCH_CHAR: \ |
|
950 |
+ if((unsigned char) p != b) \ |
|
951 |
+ match = 0; \ |
|
952 |
+ break; \ |
|
953 |
+ \ |
|
954 |
+ case CLI_MATCH_NOCASE: \ |
|
955 |
+ if((unsigned char)(p & 0xff) != cli_nocase(b)) \ |
|
956 |
+ match = 0; \ |
|
957 |
+ break; \ |
|
958 |
+ \ |
|
959 |
+ case CLI_MATCH_IGNORE: \ |
|
960 |
+ break; \ |
|
961 |
+ \ |
|
962 |
+ case CLI_MATCH_SPECIAL: \ |
|
963 |
+ /* >1 = movement, 0 = fail, <1 = resolved in branch */ \ |
|
964 |
+ if ((match = ac_findmatch_special(buffer, bp, fileoffset, length, pattern, i, \ |
|
965 |
+ specialcnt, end)) <= 0) \ |
|
966 |
+ return match; \ |
|
967 |
+ bp += match; \ |
|
968 |
+ specialcnt++; \ |
|
969 |
+ continue; /* match value includes bp++ */ \ |
|
970 |
+ \ |
|
971 |
+ case CLI_MATCH_NIBBLE_HIGH: \ |
|
972 |
+ if((unsigned char) (p & 0x00f0) != (b & 0xf0)) \ |
|
973 |
+ match = 0; \ |
|
974 |
+ break; \ |
|
975 |
+ \ |
|
976 |
+ case CLI_MATCH_NIBBLE_LOW: \ |
|
977 |
+ if((unsigned char) (p & 0x000f) != (b & 0x0f)) \ |
|
978 |
+ match = 0; \ |
|
979 |
+ break; \ |
|
980 |
+ \ |
|
981 |
+ default: \ |
|
982 |
+ cli_errmsg("ac_findmatch: Unknown wildcard 0x%x\n", wc); \ |
|
983 |
+ match = 0; \ |
|
984 | 984 |
} |
985 | 985 |
|
986 | 986 |
|
... | ... |
@@ -995,9 +995,9 @@ static int ac_findmatch_branch(const unsigned char *buffer, uint32_t offset, uin |
995 | 995 |
|
996 | 996 |
match = 1; |
997 | 997 |
for(i = pattoffset; i < pattern->length && bp < length; i++) { |
998 |
- AC_MATCH_CHAR(pattern->pattern[i],buffer[bp]); |
|
999 |
- if (!match) |
|
1000 |
- return 0; |
|
998 |
+ AC_MATCH_CHAR(pattern->pattern[i],buffer[bp]); |
|
999 |
+ if (!match) |
|
1000 |
+ return 0; |
|
1001 | 1001 |
|
1002 | 1002 |
bp++; |
1003 | 1003 |
} |
... | ... |
@@ -1149,7 +1149,7 @@ inline static int ac_findmatch(const unsigned char *buffer, uint32_t offset, uin |
1149 | 1149 |
|
1150 | 1150 |
match = ac_findmatch_branch(buffer, offset+pattern->depth, fileoffset, length, pattern, pattern->depth, specialcnt, end); |
1151 | 1151 |
if(match) |
1152 |
- return 1; |
|
1152 |
+ return 1; |
|
1153 | 1153 |
return 0; |
1154 | 1154 |
} |
1155 | 1155 |
|
... | ... |
@@ -1477,7 +1477,7 @@ int lsig_sub_matched(const struct cli_matcher *root, struct cli_ac_data *mdata, |
1477 | 1477 |
last_macroprev_match = mdata->lsigsuboff_last[lsigid1][lsigid2]; |
1478 | 1478 |
if (last_macro_match != CLI_OFF_NONE) |
1479 | 1479 |
cli_dbgmsg("Checking macro match: %u + (%u - %u) == %u\n", |
1480 |
- last_macroprev_match, smin, smax, last_macro_match); |
|
1480 |
+ last_macroprev_match, smin, smax, last_macro_match); |
|
1481 | 1481 |
|
1482 | 1482 |
if (last_macro_match == CLI_OFF_NONE || |
1483 | 1483 |
last_macroprev_match + smin > last_macro_match || |
... | ... |
@@ -1838,16 +1838,16 @@ inline static int find_paren_end(char *hexstr, char **end) |
1838 | 1838 |
|
1839 | 1839 |
*end = NULL; |
1840 | 1840 |
for (i = 0; i < strlen(hexstr); i++) { |
1841 |
- if (hexstr[i] == '(') { |
|
1842 |
- nest++; |
|
1843 |
- level++; |
|
1844 |
- } else if (hexstr[i] == ')') { |
|
1845 |
- if (!level) { |
|
1846 |
- *end = &hexstr[i]; |
|
1847 |
- break; |
|
1848 |
- } |
|
1849 |
- level--; |
|
1850 |
- } |
|
1841 |
+ if (hexstr[i] == '(') { |
|
1842 |
+ nest++; |
|
1843 |
+ level++; |
|
1844 |
+ } else if (hexstr[i] == ')') { |
|
1845 |
+ if (!level) { |
|
1846 |
+ *end = &hexstr[i]; |
|
1847 |
+ break; |
|
1848 |
+ } |
|
1849 |
+ level--; |
|
1850 |
+ } |
|
1851 | 1851 |
} |
1852 | 1852 |
|
1853 | 1853 |
return nest; |
... | ... |
@@ -1864,44 +1864,44 @@ inline static int ac_analyze_expr(char *hexstr, int *fixed_len, int *sub_len) |
1864 | 1864 |
flen = 1; |
1865 | 1865 |
slen = 0; |
1866 | 1866 |
for (i = 0; i < strlen(hexstr); i++) { |
1867 |
- if (hexstr[i] == '(') { |
|
1868 |
- flen = 0; |
|
1869 |
- level++; |
|
1870 |
- } else if (hexstr[i] == ')') { |
|
1871 |
- if (!level) { |
|
1872 |
- if (!slen) { |
|
1873 |
- slen = len; |
|
1874 |
- } else if (len != slen) { |
|
1875 |
- flen = 0; |
|
1876 |
- if (len > slen) |
|
1877 |
- slen = len; |
|
1878 |
- } |
|
1879 |
- break; |
|
1880 |
- } |
|
1881 |
- level--; |
|
1882 |
- } |
|
1883 |
- if (!level && hexstr[i] == '|') { |
|
1884 |
- if (!slen) { |
|
1885 |
- slen = len; |
|
1886 |
- } else if (len != slen) { |
|
1887 |
- flen = 0; |
|
1888 |
- if (len > slen) |
|
1889 |
- slen = len; |
|
1890 |
- } |
|
1891 |
- len = 0; |
|
1892 |
- numexpr++; |
|
1893 |
- } else { |
|
1894 |
- len++; |
|
1895 |
- } |
|
1896 |
- //cli_altnmsg("%c, %d\n", hexstr[i], len); |
|
1867 |
+ if (hexstr[i] == '(') { |
|
1868 |
+ flen = 0; |
|
1869 |
+ level++; |
|
1870 |
+ } else if (hexstr[i] == ')') { |
|
1871 |
+ if (!level) { |
|
1872 |
+ if (!slen) { |
|
1873 |
+ slen = len; |
|
1874 |
+ } else if (len != slen) { |
|
1875 |
+ flen = 0; |
|
1876 |
+ if (len > slen) |
|
1877 |
+ slen = len; |
|
1878 |
+ } |
|
1879 |
+ break; |
|
1880 |
+ } |
|
1881 |
+ level--; |
|
1882 |
+ } |
|
1883 |
+ if (!level && hexstr[i] == '|') { |
|
1884 |
+ if (!slen) { |
|
1885 |
+ slen = len; |
|
1886 |
+ } else if (len != slen) { |
|
1887 |
+ flen = 0; |
|
1888 |
+ if (len > slen) |
|
1889 |
+ slen = len; |
|
1890 |
+ } |
|
1891 |
+ len = 0; |
|
1892 |
+ numexpr++; |
|
1893 |
+ } else { |
|
1894 |
+ len++; |
|
1895 |
+ } |
|
1896 |
+ //cli_altnmsg("%c, %d\n", hexstr[i], len); |
|
1897 | 1897 |
} |
1898 | 1898 |
if (len > slen) |
1899 |
- slen = len; |
|
1899 |
+ slen = len; |
|
1900 | 1900 |
|
1901 | 1901 |
if (sub_len) |
1902 |
- *sub_len = slen; |
|
1902 |
+ *sub_len = slen; |
|
1903 | 1903 |
if (fixed_len) |
1904 |
- *fixed_len = flen; |
|
1904 |
+ *fixed_len = flen; |
|
1905 | 1905 |
|
1906 | 1906 |
return numexpr; |
1907 | 1907 |
} |
... | ... |
@@ -1915,14 +1915,14 @@ inline static int ac_addspecial_add_alt_node(const char *subexpr, struct cli_ac_ |
1915 | 1915 |
|
1916 | 1916 |
newnode = (struct cli_alt_node *)mpool_calloc(root->mempool, 1, sizeof(struct cli_alt_node)); |
1917 | 1917 |
if (!newnode) { |
1918 |
- cli_errmsg("ac_addspecial_add_alt_node: Can't allocate new alternate node\n"); |
|
1919 |
- return CL_EMEM; |
|
1918 |
+ cli_errmsg("ac_addspecial_add_alt_node: Can't allocate new alternate node\n"); |
|
1919 |
+ return CL_EMEM; |
|
1920 | 1920 |
} |
1921 | 1921 |
|
1922 | 1922 |
c = (char *)cli_mpool_hex2str(root->mempool, subexpr); |
1923 | 1923 |
if (!c) { |
1924 |
- free(newnode); |
|
1925 |
- return CL_EMALFDB; |
|
1924 |
+ free(newnode); |
|
1925 |
+ return CL_EMALFDB; |
|
1926 | 1926 |
} |
1927 | 1927 |
|
1928 | 1928 |
newnode->str = c; |
... | ... |
@@ -1932,18 +1932,18 @@ inline static int ac_addspecial_add_alt_node(const char *subexpr, struct cli_ac_ |
1932 | 1932 |
prev = &((special->alt).v_str); |
1933 | 1933 |
ins = (special->alt).v_str; |
1934 | 1934 |
while (ins) { |
1935 |
- if (ins->len == newnode->len) { |
|
1936 |
- cmp = memcmp(newnode->str, ins->str, ins->len); /* TODO - change when uint16_t is used */ |
|
1937 |
- if (cmp == 0) { /* duplicate */ |
|
1938 |
- free(newnode); |
|
1939 |
- return CL_SUCCESS; |
|
1940 |
- } else if (cmp < 0) { |
|
1941 |
- break; |
|
1942 |
- } |
|
1943 |
- } |
|
1935 |
+ if (ins->len == newnode->len) { |
|
1936 |
+ cmp = memcmp(newnode->str, ins->str, ins->len); /* TODO - change when uint16_t is used */ |
|
1937 |
+ if (cmp == 0) { /* duplicate */ |
|
1938 |
+ free(newnode); |
|
1939 |
+ return CL_SUCCESS; |
|
1940 |
+ } else if (cmp < 0) { |
|
1941 |
+ break; |
|
1942 |
+ } |
|
1943 |
+ } |
|
1944 | 1944 |
|
1945 |
- prev = &(ins->next); |
|
1946 |
- ins = ins->next; |
|
1945 |
+ prev = &(ins->next); |
|
1946 |
+ ins = ins->next; |
|
1947 | 1947 |
} |
1948 | 1948 |
|
1949 | 1949 |
*prev = newnode; |
... | ... |
@@ -1953,7 +1953,7 @@ inline static int ac_addspecial_add_alt_node(const char *subexpr, struct cli_ac_ |
1953 | 1953 |
} |
1954 | 1954 |
|
1955 | 1955 |
/* recursive special handler for expanding and adding generic alternates */ |
1956 |
-static int ac_special_altexpand(char *hexpr, char *subexpr, uint16_t maxlen, int lvl, int maxlvl, int rec, struct cli_ac_special *special, struct cli_matcher *root) |
|
1956 |
+static int ac_special_altexpand(char *hexpr, char *subexpr, uint16_t maxlen, int lvl, int maxlvl, struct cli_ac_special *special, struct cli_matcher *root) |
|
1957 | 1957 |
{ |
1958 | 1958 |
int ret, scnt = 0, numexpr; |
1959 | 1959 |
char *ept, *sexpr, *end, term; |
... | ... |
@@ -1968,120 +1968,120 @@ static int ac_special_altexpand(char *hexpr, char *subexpr, uint16_t maxlen, int |
1968 | 1968 |
|
1969 | 1969 |
/* while there are expressions to resolve */ |
1970 | 1970 |
while (scnt < numexpr) { |
1971 |
- scnt++; |
|
1972 |
- while ((*ept != '(') && (*ept != '|') && (*ept != ')') && (*ept != '\0')) |
|
1973 |
- ept++; |
|
1974 |
- |
|
1975 |
- /* check for invalid negation */ |
|
1976 |
- term = *ept; |
|
1977 |
- if ((*ept == '(') && (ept >= hexpr+1)) { |
|
1978 |
- if (ept[-1] == '!') { |
|
1979 |
- cli_errmsg("ac_special_altexpand: Generic alternates cannot contain negations\n"); |
|
1980 |
- return CL_EMALFDB; |
|
1981 |
- } |
|
1982 |
- } |
|
1983 |
- |
|
1984 |
- /* appended token */ |
|
1985 |
- *ept = 0; |
|
1986 |
- if (cli_strlcat(subexpr, sexpr, maxlen) >= maxlen) { |
|
1987 |
- cli_errmsg("ac_special_altexpand: Unexpected expression larger than expected\n"); |
|
1988 |
- return CL_EMEM; |
|
1989 |
- } |
|
1990 |
- *ept++ = term; |
|
1991 |
- |
|
1992 |
- sexpr = ept; |
|
1993 |
- //cli_altnmsg("ac_special_altexpand: %s\n", subexpr); |
|
1994 |
- |
|
1995 |
- if (term == '|') { |
|
1996 |
- //cli_altnmsg("ept: %s\n", ept); |
|
1997 |
- if (lvl == 0) { |
|
1998 |
- cli_altnmsg("export: %s\n", subexpr); |
|
1999 |
- if ((ret = ac_addspecial_add_alt_node(subexpr, special, root)) != CL_SUCCESS) |
|
2000 |
- return ret; |
|
2001 |
- } else { |
|
2002 |
- find_paren_end(ept, &end); |
|
2003 |
- if (!end) { |
|
2004 |
- cli_errmsg("ac_special_altexpand: Missing closing parenthesis\n"); |
|
2005 |
- return CL_EMALFDB; |
|
2006 |
- } |
|
2007 |
- end++; |
|
2008 |
- |
|
2009 |
- //cli_altnmsg("descending recursive call on %s\n", end); |
|
1971 |
+ scnt++; |
|
1972 |
+ while ((*ept != '(') && (*ept != '|') && (*ept != ')') && (*ept != '\0')) |
|
1973 |
+ ept++; |
|
1974 |
+ |
|
1975 |
+ /* check for invalid negation */ |
|
1976 |
+ term = *ept; |
|
1977 |
+ if ((*ept == '(') && (ept >= hexpr+1)) { |
|
1978 |
+ if (ept[-1] == '!') { |
|
1979 |
+ cli_errmsg("ac_special_altexpand: Generic alternates cannot contain negations\n"); |
|
1980 |
+ return CL_EMALFDB; |
|
1981 |
+ } |
|
1982 |
+ } |
|
1983 |
+ |
|
1984 |
+ /* appended token */ |
|
1985 |
+ *ept = 0; |
|
1986 |
+ if (cli_strlcat(subexpr, sexpr, maxlen) >= maxlen) { |
|
1987 |
+ cli_errmsg("ac_special_altexpand: Unexpected expression larger than expected\n"); |
|
1988 |
+ return CL_EMEM; |
|
1989 |
+ } |
|
1990 |
+ *ept++ = term; |
|
1991 |
+ |
|
1992 |
+ sexpr = ept; |
|
1993 |
+ //cli_altnmsg("ac_special_altexpand: %s\n", subexpr); |
|
1994 |
+ |
|
1995 |
+ if (term == '|') { |
|
1996 |
+ //cli_altnmsg("ept: %s\n", ept); |
|
1997 |
+ if (lvl == 0) { |
|
1998 |
+ cli_altnmsg("export: %s\n", subexpr); |
|
1999 |
+ if ((ret = ac_addspecial_add_alt_node(subexpr, special, root)) != CL_SUCCESS) |
|
2000 |
+ return ret; |
|
2001 |
+ } else { |
|
2002 |
+ find_paren_end(ept, &end); |
|
2003 |
+ if (!end) { |
|
2004 |
+ cli_errmsg("ac_special_altexpand: Missing closing parenthesis\n"); |
|
2005 |
+ return CL_EMALFDB; |
|
2006 |
+ } |
|
2007 |
+ end++; |
|
2008 |
+ |
|
2009 |
+ //cli_altnmsg("descending recursive call on %s\n", end); |
|
2010 | 2010 |
if ((ret = ac_special_altexpand(end, subexpr, maxlen, lvl-1, lvl, special, root)) != CL_SUCCESS) |
2011 |
- return ret; |
|
2011 |
+ return ret; |
|
2012 | 2012 |
//cli_altnmsg("return descending recursive call\n"); |
2013 |
- } |
|
2014 |
- |
|
2015 |
- *fp = 0; |
|
2016 |
- } else if (term == ')') { |
|
2017 |
- //cli_altnmsg("ept: %s\n", ept); |
|
2018 |
- if (lvl == 0) { |
|
2019 |
- cli_errmsg("ac_special_altexpand: Unexpected closing parenthesis\n"); |
|
2020 |
- return CL_EPARSE; |
|
2021 |
- } |
|
2022 |
- |
|
2023 |
- //cli_altnmsg("descending recursive call\n"); |
|
2024 |
- if ((ret = ac_special_altexpand(ept, subexpr, maxlen, lvl-1, lvl, special, root)) != CL_SUCCESS) |
|
2025 |
- return ret; |
|
2026 |
- //cli_altnmsg("return descending recursive call\n"); |
|
2027 |
- break; |
|
2028 |
- } else if (term == '(') { |
|
2029 |
- int inner, found; |
|
2030 |
- find_paren_end(ept, &end); |
|
2031 |
- if (!end) { |
|
2032 |
- cli_errmsg("ac_special_altexpand: Missing closing parenthesis\n"); |
|
2033 |
- return CL_EMALFDB; |
|
2034 |
- } |
|
2035 |
- end++; |
|
2036 |
- |
|
2037 |
- //cli_altnmsg("ascending recursive call\n"); |
|
2038 |
- if ((ret = ac_special_altexpand(ept, subexpr, maxlen, lvl+1, lvl+1, special, root)) != CL_SUCCESS) |
|
2039 |
- return ret; |
|
2040 |
- //cli_altnmsg("return ascending recursive call\n"); |
|
2041 |
- |
|
2042 |
- /* move ept to end of current alternate expression */ |
|
2043 |
- ept = end; |
|
2044 |
- inner = 0; |
|
2045 |
- found = 0; |
|
2046 |
- while (!found && *ept != '\0') { |
|
2047 |
- switch(*ept) { |
|
2048 |
- case '|': |
|
2049 |
- if (!inner) |
|
2050 |
- found = 1; |
|
2051 |
- break; |
|
2052 |
- case '(': |
|
2053 |
- inner++; |
|
2054 |
- break; |
|
2055 |
- case ')': |
|
2056 |
- inner--; |
|
2057 |
- break; |
|
2058 |
- } |
|
2059 |
- ept++; |
|
2060 |
- } |
|
2061 |
- if (*ept == '|') |
|
2062 |
- ept++; |
|
2063 |
- |
|
2064 |
- sexpr = ept; |
|
2065 |
- *fp = 0; |
|
2066 |
- } else if (term == '\0') { |
|
2067 |
- cli_altnmsg("export: %s\n", subexpr); |
|
2068 |
- if ((ret = ac_addspecial_add_alt_node(subexpr, special, root)) != CL_SUCCESS) |
|
2069 |
- return ret; |
|
2070 |
- break; |
|
2071 |
- } |
|
2072 |
- |
|
2073 |
- //cli_altnmsg("%d %d\n", lvl, maxlvl); |
|
2074 |
- if (lvl != maxlvl) |
|
2075 |
- return CL_SUCCESS; |
|
2013 |
+ } |
|
2014 |
+ |
|
2015 |
+ *fp = 0; |
|
2016 |
+ } else if (term == ')') { |
|
2017 |
+ //cli_altnmsg("ept: %s\n", ept); |
|
2018 |
+ if (lvl == 0) { |
|
2019 |
+ cli_errmsg("ac_special_altexpand: Unexpected closing parenthesis\n"); |
|
2020 |
+ return CL_EPARSE; |
|
2021 |
+ } |
|
2022 |
+ |
|
2023 |
+ //cli_altnmsg("descending recursive call\n"); |
|
2024 |
+ if ((ret = ac_special_altexpand(ept, subexpr, maxlen, lvl-1, lvl, special, root)) != CL_SUCCESS) |
|
2025 |
+ return ret; |
|
2026 |
+ //cli_altnmsg("return descending recursive call\n"); |
|
2027 |
+ break; |
|
2028 |
+ } else if (term == '(') { |
|
2029 |
+ int inner, found; |
|
2030 |
+ find_paren_end(ept, &end); |
|
2031 |
+ if (!end) { |
|
2032 |
+ cli_errmsg("ac_special_altexpand: Missing closing parenthesis\n"); |
|
2033 |
+ return CL_EMALFDB; |
|
2034 |
+ } |
|
2035 |
+ end++; |
|
2036 |
+ |
|
2037 |
+ //cli_altnmsg("ascending recursive call\n"); |
|
2038 |
+ if ((ret = ac_special_altexpand(ept, subexpr, maxlen, lvl+1, lvl+1, special, root)) != CL_SUCCESS) |
|
2039 |
+ return ret; |
|
2040 |
+ //cli_altnmsg("return ascending recursive call\n"); |
|
2041 |
+ |
|
2042 |
+ /* move ept to end of current alternate expression */ |
|
2043 |
+ ept = end; |
|
2044 |
+ inner = 0; |
|
2045 |
+ found = 0; |
|
2046 |
+ while (!found && *ept != '\0') { |
|
2047 |
+ switch(*ept) { |
|
2048 |
+ case '|': |
|
2049 |
+ if (!inner) |
|
2050 |
+ found = 1; |
|
2051 |
+ break; |
|
2052 |
+ case '(': |
|
2053 |
+ inner++; |
|
2054 |
+ break; |
|
2055 |
+ case ')': |
|
2056 |
+ inner--; |
|
2057 |
+ break; |
|
2058 |
+ } |
|
2059 |
+ ept++; |
|
2060 |
+ } |
|
2061 |
+ if (*ept == '|') |
|
2062 |
+ ept++; |
|
2063 |
+ |
|
2064 |
+ sexpr = ept; |
|
2065 |
+ *fp = 0; |
|
2066 |
+ } else if (term == '\0') { |
|
2067 |
+ cli_altnmsg("export: %s\n", subexpr); |
|
2068 |
+ if ((ret = ac_addspecial_add_alt_node(subexpr, special, root)) != CL_SUCCESS) |
|
2069 |
+ return ret; |
|
2070 |
+ break; |
|
2071 |
+ } |
|
2072 |
+ |
|
2073 |
+ //cli_altnmsg("%d %d\n", lvl, maxlvl); |
|
2074 |
+ if (lvl != maxlvl) |
|
2075 |
+ return CL_SUCCESS; |
|
2076 | 2076 |
} |
2077 | 2077 |
if (scnt != numexpr) { |
2078 |
- //cli_altnmsg("scnt %d numexpr %d\n", scnt, numexpr); |
|
2079 |
- cli_errmsg("ac_addspecial: Mismatch in parsed and expected signature\n"); |
|
2080 |
- return CL_EMALFDB; |
|
2078 |
+ //cli_altnmsg("scnt %d numexpr %d\n", scnt, numexpr); |
|
2079 |
+ cli_errmsg("ac_addspecial: Mismatch in parsed and expected signature\n"); |
|
2080 |
+ return CL_EMALFDB; |
|
2081 | 2081 |
} |
2082 | 2082 |
#if ALTN_DEBUG |
2083 | 2083 |
else |
2084 |
- cli_altnmsg("subexpr cnt OK\n"); |
|
2084 |
+ cli_altnmsg("subexpr cnt OK\n"); |
|
2085 | 2085 |
#endif |
2086 | 2086 |
|
2087 | 2087 |
return CL_SUCCESS; |
... | ... |
@@ -2096,8 +2096,8 @@ inline static int ac_special_altstr(const char *hexpr, struct cli_ac_special *sp |
2096 | 2096 |
//cli_errmsg("called ac_special_altstr\n"); |
2097 | 2097 |
|
2098 | 2098 |
if (!(hexprcpy = cli_strdup(hexpr))) { |
2099 |
- cli_errmsg("ac_special_altstr: Can't duplicate alternate expression\n"); |
|
2100 |
- return CL_EDUP; |
|
2099 |
+ cli_errmsg("ac_special_altstr: Can't duplicate alternate expression\n"); |
|
2100 |
+ return CL_EDUP; |
|
2101 | 2101 |
} |
2102 | 2102 |
|
2103 | 2103 |
len = strlen(hexpr); |
... | ... |
@@ -2109,88 +2109,88 @@ inline static int ac_special_altstr(const char *hexpr, struct cli_ac_special *sp |
2109 | 2109 |
cli_altnmsg("-----------------------------------\n"); |
2110 | 2110 |
|
2111 | 2111 |
if (fixed) { |
2112 |
- special->num = 0; |
|
2113 |
- special->len = slen / 2; |
|
2114 |
- /* single-bytes are len 2 in hex */ |
|
2115 |
- if (slen == 2) { |
|
2116 |
- cli_altnmsg("ac_special_altstr: discovered AC_SPECIAL_ALT_CHAR\n"); |
|
2117 |
- special->type = AC_SPECIAL_ALT_CHAR; |
|
2118 |
- (special->alt).byte = (unsigned char *) mpool_malloc(root->mempool, num); |
|
2119 |
- if (!((special->alt).byte)) { |
|
2120 |
- cli_errmsg("cli_ac_special_altstr: Can't allocate newspecial->str\n"); |
|
2121 |
- free(hexprcpy); |
|
2122 |
- return CL_EMEM; |
|
2123 |
- } |
|
2124 |
- } else { |
|
2125 |
- cli_altnmsg("ac_special_altstr: discovered AC_SPECIAL_ALT_STR_FIXED\n"); |
|
2126 |
- special->type = AC_SPECIAL_ALT_STR_FIXED; |
|
2127 |
- (special->alt).f_str = (unsigned char **) mpool_malloc(root->mempool, num); |
|
2128 |
- if (!((special->alt).f_str)) { |
|
2129 |
- cli_errmsg("cli_ac_special_altstr: Can't allocate newspecial->str\n"); |
|
2130 |
- free(hexprcpy); |
|
2131 |
- return CL_EMEM; |
|
2132 |
- } |
|
2133 |
- } |
|
2134 |
- |
|
2135 |
- for (i = 0; i < num; i++) { |
|
2136 |
- if (num == 1) { |
|
2137 |
- c = (char *) cli_mpool_hex2str(root->mempool, hexprcpy); |
|
2138 |
- } else { |
|
2139 |
- if(!(h = cli_strtok(hexprcpy, i, "|"))) { |
|
2140 |
- free(hexprcpy); |
|
2141 |
- return CL_EMEM; |
|
2142 |
- } |
|
2143 |
- c = (char *) cli_mpool_hex2str(root->mempool, h); |
|
2144 |
- free(h); |
|
2145 |
- } |
|
2146 |
- if (!c) { |
|
2147 |
- free(hexprcpy); |
|
2148 |
- return CL_EMALFDB; |
|
2149 |
- } |
|
2150 |
- |
|
2151 |
- if (special->type == AC_SPECIAL_ALT_CHAR) { |
|
2152 |
- (special->alt).byte[i] = *c; |
|
2153 |
- mpool_free(root->mempool, c); |
|
2154 |
- } else { |
|
2155 |
- (special->alt).f_str[i] = c; |
|
2156 |
- } |
|
2157 |
- special->num++; |
|
2158 |
- } |
|
2159 |
- /* sorting byte alternates */ |
|
2160 |
- if (special->num > 1 && special->type == AC_SPECIAL_ALT_CHAR) |
|
2161 |
- cli_qsort((special->alt).byte, special->num, sizeof(unsigned char), qcompare); |
|
2162 |
- /* TODO - sorting str alternates */ |
|
2112 |
+ special->num = 0; |
|
2113 |
+ special->len = slen / 2; |
|
2114 |
+ /* single-bytes are len 2 in hex */ |
|
2115 |
+ if (slen == 2) { |
|
2116 |
+ cli_altnmsg("ac_special_altstr: discovered AC_SPECIAL_ALT_CHAR\n"); |
|
2117 |
+ special->type = AC_SPECIAL_ALT_CHAR; |
|
2118 |
+ (special->alt).byte = (unsigned char *) mpool_malloc(root->mempool, num); |
|
2119 |
+ if (!((special->alt).byte)) { |
|
2120 |
+ cli_errmsg("cli_ac_special_altstr: Can't allocate newspecial->str\n"); |
|
2121 |
+ free(hexprcpy); |
|
2122 |
+ return CL_EMEM; |
|
2123 |
+ } |
|
2124 |
+ } else { |
|
2125 |
+ cli_altnmsg("ac_special_altstr: discovered AC_SPECIAL_ALT_STR_FIXED\n"); |
|
2126 |
+ special->type = AC_SPECIAL_ALT_STR_FIXED; |
|
2127 |
+ (special->alt).f_str = (unsigned char **) mpool_malloc(root->mempool, num); |
|
2128 |
+ if (!((special->alt).f_str)) { |
|
2129 |
+ cli_errmsg("cli_ac_special_altstr: Can't allocate newspecial->str\n"); |
|
2130 |
+ free(hexprcpy); |
|
2131 |
+ return CL_EMEM; |
|
2132 |
+ } |
|
2133 |
+ } |
|
2134 |
+ |
|
2135 |
+ for (i = 0; i < num; i++) { |
|
2136 |
+ if (num == 1) { |
|
2137 |
+ c = (char *) cli_mpool_hex2str(root->mempool, hexprcpy); |
|
2138 |
+ } else { |
|
2139 |
+ if(!(h = cli_strtok(hexprcpy, i, "|"))) { |
|
2140 |
+ free(hexprcpy); |
|
2141 |
+ return CL_EMEM; |
|
2142 |
+ } |
|
2143 |
+ c = (char *) cli_mpool_hex2str(root->mempool, h); |
|
2144 |
+ free(h); |
|
2145 |
+ } |
|
2146 |
+ if (!c) { |
|
2147 |
+ free(hexprcpy); |
|
2148 |
+ return CL_EMALFDB; |
|
2149 |
+ } |
|
2150 |
+ |
|
2151 |
+ if (special->type == AC_SPECIAL_ALT_CHAR) { |
|
2152 |
+ (special->alt).byte[i] = *c; |
|
2153 |
+ mpool_free(root->mempool, c); |
|
2154 |
+ } else { |
|
2155 |
+ (special->alt).f_str[i] = c; |
|
2156 |
+ } |
|
2157 |
+ special->num++; |
|
2158 |
+ } |
|
2159 |
+ /* sorting byte alternates */ |
|
2160 |
+ if (special->num > 1 && special->type == AC_SPECIAL_ALT_CHAR) |
|
2161 |
+ cli_qsort((special->alt).byte, special->num, sizeof(unsigned char), qcompare); |
|
2162 |
+ /* TODO - sorting str alternates */ |
|
2163 | 2163 |
} else { /* generic alternates */ |
2164 |
- char *subexpr; |
|
2165 |
- cli_altnmsg("ac_special_altstr: discovered AC_SPECIAL_ALT_STR\n"); |
|
2166 |
- if (special->negative) { |
|
2167 |
- cli_errmsg("ac_special_altstr: Can't apply negation operation to generic alternate strings\n"); |
|
2168 |
- free(hexprcpy); |
|
2169 |
- return CL_EMALFDB; |
|
2170 |
- } |
|
2164 |
+ char *subexpr; |
|
2165 |
+ cli_altnmsg("ac_special_altstr: discovered AC_SPECIAL_ALT_STR\n"); |
|
2166 |
+ if (special->negative) { |
|
2167 |
+ cli_errmsg("ac_special_altstr: Can't apply negation operation to generic alternate strings\n"); |
|
2168 |
+ free(hexprcpy); |
|
2169 |
+ return CL_EMALFDB; |
|
2170 |
+ } |
|
2171 | 2171 |
|
2172 |
- special->type = AC_SPECIAL_ALT_STR; |
|
2172 |
+ special->type = AC_SPECIAL_ALT_STR; |
|
2173 | 2173 |
|
2174 |
- /* allocate reusable subexpr */ |
|
2175 |
- if (!(subexpr = cli_calloc(slen+1, sizeof(char)))) { |
|
2176 |
- cli_errmsg("ac_special_altstr: Can't allocate subexpr container\n"); |
|
2177 |
- return CL_EMEM; |
|
2178 |
- } |
|
2174 |
+ /* allocate reusable subexpr */ |
|
2175 |
+ if (!(subexpr = cli_calloc(slen+1, sizeof(char)))) { |
|
2176 |
+ cli_errmsg("ac_special_altstr: Can't allocate subexpr container\n"); |
|
2177 |
+ return CL_EMEM; |
|
2178 |
+ } |
|
2179 | 2179 |
|
2180 |
- // static int ac_special_altexpand(char *hexpr, char *subexpr, uint16_t maxlen, int lvl, int maxlvl, struct cli_ac_special *special, struct cli_matcher *root) |
|
2181 |
- ret = ac_special_altexpand(hexprcpy, subexpr, slen+1, 0, 0, special, root); |
|
2180 |
+ // static int ac_special_altexpand(char *hexpr, char *subexpr, uint16_t maxlen, int lvl, int maxlvl, struct cli_ac_special *special, struct cli_matcher *root) |
|
2181 |
+ ret = ac_special_altexpand(hexprcpy, subexpr, slen+1, 0, 0, special, root); |
|
2182 | 2182 |
|
2183 | 2183 |
#if ALTN_DEBUG |
2184 |
- struct cli_alt_node *node = (special->alt).v_str; |
|
2185 |
- while (node) { |
|
2186 |
- cli_errmsg("%d: %s\n", node->len, node->str); |
|
2187 |
- node = node->next; |
|
2188 |
- } |
|
2184 |
+ struct cli_alt_node *node = (special->alt).v_str; |
|
2185 |
+ while (node) { |
|
2186 |
+ cli_errmsg("%d: %s\n", node->len, node->str); |
|
2187 |
+ node = node->next; |
|
2188 |
+ } |
|
2189 | 2189 |
#endif |
2190 | 2190 |
|
2191 |
- free(subexpr); |
|
2192 |
- free(hexprcpy); |
|
2193 |
- return ret; |
|
2191 |
+ free(subexpr); |
|
2192 |
+ free(hexprcpy); |
|
2193 |
+ return ret; |
|
2194 | 2194 |
} |
2195 | 2195 |
|
2196 | 2196 |
free(hexprcpy); |
... | ... |
@@ -2331,152 +2331,152 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex |
2331 | 2331 |
} |
2332 | 2332 |
|
2333 | 2333 |
if(strchr(hexsig, '(')) { |
2334 |
- char *hexnew, *start; |
|
2335 |
- uint8_t nest; |
|
2336 |
- size_t hexnewsz; |
|
2337 |
- |
|
2338 |
- if(hex) { |
|
2339 |
- hexcpy = hex; |
|
2340 |
- } else if(!(hexcpy = cli_strdup(hexsig))) { |
|
2341 |
- mpool_free(root->mempool, new); |
|
2342 |
- return CL_EMEM; |
|
2343 |
- } |
|
2344 |
- |
|
2345 |
- hexnewsz = strlen(hexsig) + 1; |
|
2346 |
- if(!(hexnew = (char *) cli_calloc(1, hexnewsz))) { |
|
2347 |
- free(new); |
|
2348 |
- free(hexcpy); |
|
2349 |
- return CL_EMEM; |
|
2350 |
- } |
|
2351 |
- |
|
2352 |
- start = pt = hexcpy; |
|
2353 |
- while((pt = strchr(start, '('))) { |
|
2354 |
- *pt++ = 0; |
|
2355 |
- |
|
2356 |
- if(!start) { |
|
2357 |
- error = CL_EMALFDB; |
|
2358 |
- break; |
|
2359 |
- } |
|
2360 |
- newspecial = (struct cli_ac_special *) mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_special)); |
|
2361 |
- if(!newspecial) { |
|
2362 |
- cli_errmsg("cli_ac_addsig: Can't allocate newspecial\n"); |
|
2363 |
- error = CL_EMEM; |
|
2364 |
- break; |
|
2365 |
- } |
|
2366 |
- if(pt >= hexcpy + 2) { |
|
2367 |
- if(pt[-2] == '!') { |
|
2368 |
- newspecial->negative = 1; |
|
2369 |
- pt[-2] = 0; |
|
2370 |
- } |
|
2371 |
- } |
|
2372 |
- cli_strlcat(hexnew, start, hexnewsz); |
|
2373 |
- |
|
2374 |
- nest = find_paren_end(pt, &start); |
|
2375 |
- if(!start) { |
|
2376 |
- cli_errmsg("cli_ac_addsig: Missing closing parenthesis\n"); |
|
2377 |
- mpool_free(root->mempool, newspecial); |
|
2378 |
- error = CL_EMALFDB; |
|
2379 |
- break; |
|
2380 |
- } |
|
2381 |
- *start++ = 0; |
|
2382 |
- if(!strlen(pt)) { |
|
2383 |
- cli_errmsg("cli_ac_addsig: Empty block\n"); |
|
2384 |
- mpool_free(root->mempool, newspecial); |
|
2385 |
- error = CL_EMALFDB; |
|
2386 |
- break; |
|
2387 |
- } |
|
2388 |
- |
|
2389 |
- if (nest > ARBITRARY_NEST_LIMIT) { |
|
2390 |
- cli_errmsg("ac_addspecial: We've gone too deep!\n"); |
|
2391 |
- free(hexcpy); |
|
2392 |
- return CL_EMALFDB; |
|
2393 |
- } |
|
2394 |
- |
|
2395 |
- if(!strcmp(pt, "B")) { |
|
2396 |
- if(!*start) { |
|
2397 |
- new->boundary |= AC_BOUNDARY_RIGHT; |
|
2398 |
- if(newspecial->negative) |
|
2399 |
- new->boundary |= AC_BOUNDARY_RIGHT_NEGATIVE; |
|
2400 |
- mpool_free(root->mempool, newspecial); |
|
2401 |
- continue; |
|
2402 |
- } else if(pt - 1 == hexcpy) { |
|
2403 |
- new->boundary |= AC_BOUNDARY_LEFT; |
|
2404 |
- if(newspecial->negative) |
|
2405 |
- new->boundary |= AC_BOUNDARY_LEFT_NEGATIVE; |
|
2406 |
- mpool_free(root->mempool, newspecial); |
|
2407 |
- continue; |
|
2408 |
- } |
|
2409 |
- } else if(!strcmp(pt, "L")) { |
|
2410 |
- if(!*start) { |
|
2411 |
- new->boundary |= AC_LINE_MARKER_RIGHT; |
|
2412 |
- if(newspecial->negative) |
|
2413 |
- new->boundary |= AC_LINE_MARKER_RIGHT_NEGATIVE; |
|
2414 |
- mpool_free(root->mempool, newspecial); |
|
2415 |
- continue; |
|
2416 |
- } else if(pt - 1 == hexcpy) { |
|
2417 |
- new->boundary |= AC_LINE_MARKER_LEFT; |
|
2418 |
- if(newspecial->negative) |
|
2419 |
- new->boundary |= AC_LINE_MARKER_LEFT_NEGATIVE; |
|
2420 |
- mpool_free(root->mempool, newspecial); |
|
2421 |
- continue; |
|
2422 |
- } |
|
2423 |
- } else if(!strcmp(pt, "W")) { |
|
2424 |
- if(!*start) { |
|
2425 |
- new->boundary |= AC_WORD_MARKER_RIGHT; |
|
2426 |
- if(newspecial->negative) |
|
2427 |
- new->boundary |= AC_WORD_MARKER_RIGHT_NEGATIVE; |
|
2428 |
- mpool_free(root->mempool, newspecial); |
|
2429 |
- continue; |
|
2430 |
- } else if(pt - 1 == hexcpy) { |
|
2431 |
- new->boundary |= AC_WORD_MARKER_LEFT; |
|
2432 |
- if(newspecial->negative) |
|
2433 |
- new->boundary |= AC_WORD_MARKER_LEFT_NEGATIVE; |
|
2434 |
- mpool_free(root->mempool, newspecial); |
|
2435 |
- continue; |
|
2436 |
- } |
|
2437 |
- } |
|
2438 |
- cli_strlcat(hexnew, "()", hexnewsz); |
|
2439 |
- new->special++; |
|
2440 |
- newtable = (struct cli_ac_special **) mpool_realloc(root->mempool, new->special_table, new->special * sizeof(struct cli_ac_special *)); |
|
2441 |
- if(!newtable) { |
|
2442 |
- new->special--; |
|
2443 |
- mpool_free(root->mempool, newspecial); |
|
2444 |
- cli_errmsg("cli_ac_addsig: Can't realloc new->special_table\n"); |
|
2445 |
- error = CL_EMEM; |
|
2446 |
- break; |
|
2447 |
- } |
|
2448 |
- newtable[new->special - 1] = newspecial; |
|
2449 |
- new->special_table = newtable; |
|
2450 |
- |
|
2451 |
- if(!strcmp(pt, "B")) { |
|
2452 |
- newspecial->type = AC_SPECIAL_BOUNDARY; |
|
2453 |
- } else if(!strcmp(pt, "L")) { |
|
2454 |
- newspecial->type = AC_SPECIAL_LINE_MARKER; |
|
2455 |
- } else if(!strcmp(pt, "W")) { |
|
2456 |
- newspecial->type = AC_SPECIAL_WORD_MARKER; |
|
2457 |
- } else { |
|
2458 |
- if ((ret = ac_special_altstr(pt, newspecial, root)) != CL_SUCCESS) { |
|
2459 |
- //cli_altnmsg("returned ac_special_altstr %d\n", ret); |
|
2460 |
- error = ret; |
|
2461 |
- break; |
|
2462 |
- } |
|
2463 |
- } |
|
2464 |
- } |
|
2465 |
- |
|
2466 |
- if(start) |
|
2467 |
- cli_strlcat(hexnew, start, hexnewsz); |
|
2468 |
- |
|
2469 |
- hex = hexnew; |
|
2470 |
- free(hexcpy); |
|
2471 |
- |
|
2472 |
- if(error) { |
|
2473 |
- free(hex); |
|
2474 |
- if(new->special) { |
|
2475 |
- mpool_ac_free_special(root->mempool, new); |
|
2476 |
- } |
|
2477 |
- mpool_free(root->mempool, new); |
|
2478 |
- return error; |
|
2479 |
- } |
|
2334 |
+ char *hexnew, *start; |
|
2335 |
+ uint8_t nest; |
|
2336 |
+ size_t hexnewsz; |
|
2337 |
+ |
|
2338 |
+ if(hex) { |
|
2339 |
+ hexcpy = hex; |
|
2340 |
+ } else if(!(hexcpy = cli_strdup(hexsig))) { |
|
2341 |
+ mpool_free(root->mempool, new); |
|
2342 |
+ return CL_EMEM; |
|
2343 |
+ } |
|
2344 |
+ |
|
2345 |
+ hexnewsz = strlen(hexsig) + 1; |
|
2346 |
+ if(!(hexnew = (char *) cli_calloc(1, hexnewsz))) { |
|
2347 |
+ free(new); |
|
2348 |
+ free(hexcpy); |
|
2349 |
+ return CL_EMEM; |
|
2350 |
+ } |
|
2351 |
+ |
|
2352 |
+ start = pt = hexcpy; |
|
2353 |
+ while((pt = strchr(start, '('))) { |
|
2354 |
+ *pt++ = 0; |
|
2355 |
+ |
|
2356 |
+ if(!start) { |
|
2357 |
+ error = CL_EMALFDB; |
|
2358 |
+ break; |
|
2359 |
+ } |
|
2360 |
+ newspecial = (struct cli_ac_special *) mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_special)); |
|
2361 |
+ if(!newspecial) { |
|
2362 |
+ cli_errmsg("cli_ac_addsig: Can't allocate newspecial\n"); |
|
2363 |
+ error = CL_EMEM; |
|
2364 |
+ break; |
|
2365 |
+ } |
|
2366 |
+ if(pt >= hexcpy + 2) { |
|
2367 |
+ if(pt[-2] == '!') { |
|
2368 |
+ newspecial->negative = 1; |
|
2369 |
+ pt[-2] = 0; |
|
2370 |
+ } |
|
2371 |
+ } |
|
2372 |
+ cli_strlcat(hexnew, start, hexnewsz); |
|
2373 |
+ |
|
2374 |
+ nest = find_paren_end(pt, &start); |
|
2375 |
+ if(!start) { |
|
2376 |
+ cli_errmsg("cli_ac_addsig: Missing closing parenthesis\n"); |
|
2377 |
+ mpool_free(root->mempool, newspecial); |
|
2378 |
+ error = CL_EMALFDB; |
|
2379 |
+ break; |
|
2380 |
+ } |
|
2381 |
+ *start++ = 0; |
|
2382 |
+ if(!strlen(pt)) { |
|
2383 |
+ cli_errmsg("cli_ac_addsig: Empty block\n"); |
|
2384 |
+ mpool_free(root->mempool, newspecial); |
|
2385 |
+ error = CL_EMALFDB; |
|
2386 |
+ break; |
|
2387 |
+ } |
|
2388 |
+ |
|
2389 |
+ if (nest > ARBITRARY_NEST_LIMIT) { |
|
2390 |
+ cli_errmsg("ac_addspecial: We've gone too deep!\n"); |
|
2391 |
+ free(hexcpy); |
|
2392 |
+ return CL_EMALFDB; |
|
2393 |
+ } |
|
2394 |
+ |
|
2395 |
+ if(!strcmp(pt, "B")) { |
|
2396 |
+ if(!*start) { |
|
2397 |
+ new->boundary |= AC_BOUNDARY_RIGHT; |
|
2398 |
+ if(newspecial->negative) |
|
2399 |
+ new->boundary |= AC_BOUNDARY_RIGHT_NEGATIVE; |
|
2400 |
+ mpool_free(root->mempool, newspecial); |
|
2401 |
+ continue; |
|
2402 |
+ } else if(pt - 1 == hexcpy) { |
|
2403 |
+ new->boundary |= AC_BOUNDARY_LEFT; |
|
2404 |
+ if(newspecial->negative) |
|
2405 |
+ new->boundary |= AC_BOUNDARY_LEFT_NEGATIVE; |
|
2406 |
+ mpool_free(root->mempool, newspecial); |
|
2407 |
+ continue; |
|
2408 |
+ } |
|
2409 |
+ } else if(!strcmp(pt, "L")) { |
|
2410 |
+ if(!*start) { |
|
2411 |
+ new->boundary |= AC_LINE_MARKER_RIGHT; |
|
2412 |
+ if(newspecial->negative) |
|
2413 |
+ new->boundary |= AC_LINE_MARKER_RIGHT_NEGATIVE; |
|
2414 |
+ mpool_free(root->mempool, newspecial); |
|
2415 |
+ continue; |
|
2416 |
+ } else if(pt - 1 == hexcpy) { |
|
2417 |
+ new->boundary |= AC_LINE_MARKER_LEFT; |
|
2418 |
+ if(newspecial->negative) |
|
2419 |
+ new->boundary |= AC_LINE_MARKER_LEFT_NEGATIVE; |
|
2420 |
+ mpool_free(root->mempool, newspecial); |
|
2421 |
+ continue; |
|
2422 |
+ } |
|
2423 |
+ } else if(!strcmp(pt, "W")) { |
|
2424 |
+ if(!*start) { |
|
2425 |
+ new->boundary |= AC_WORD_MARKER_RIGHT; |
|
2426 |
+ if(newspecial->negative) |
|
2427 |
+ new->boundary |= AC_WORD_MARKER_RIGHT_NEGATIVE; |
|
2428 |
+ mpool_free(root->mempool, newspecial); |
|
2429 |
+ continue; |
|
2430 |
+ } else if(pt - 1 == hexcpy) { |
|
2431 |
+ new->boundary |= AC_WORD_MARKER_LEFT; |
|
2432 |
+ if(newspecial->negative) |
|
2433 |
+ new->boundary |= AC_WORD_MARKER_LEFT_NEGATIVE; |
|
2434 |
+ mpool_free(root->mempool, newspecial); |
|
2435 |
+ continue; |
|
2436 |
+ } |
|
2437 |
+ } |
|
2438 |
+ cli_strlcat(hexnew, "()", hexnewsz); |
|
2439 |
+ new->special++; |
|
2440 |
+ newtable = (struct cli_ac_special **) mpool_realloc(root->mempool, new->special_table, new->special * sizeof(struct cli_ac_special *)); |
|
2441 |
+ if(!newtable) { |
|
2442 |
+ new->special--; |
|
2443 |
+ mpool_free(root->mempool, newspecial); |
|
2444 |
+ cli_errmsg("cli_ac_addsig: Can't realloc new->special_table\n"); |
|
2445 |
+ error = CL_EMEM; |
|
2446 |
+ break; |
|
2447 |
+ } |
|
2448 |
+ newtable[new->special - 1] = newspecial; |
|
2449 |
+ new->special_table = newtable; |
|
2450 |
+ |
|
2451 |
+ if(!strcmp(pt, "B")) { |
|
2452 |
+ newspecial->type = AC_SPECIAL_BOUNDARY; |
|
2453 |
+ } else if(!strcmp(pt, "L")) { |
|
2454 |
+ newspecial->type = AC_SPECIAL_LINE_MARKER; |
|
2455 |
+ } else if(!strcmp(pt, "W")) { |
|
2456 |
+ newspecial->type = AC_SPECIAL_WORD_MARKER; |
|
2457 |
+ } else { |
|
2458 |
+ if ((ret = ac_special_altstr(pt, newspecial, root)) != CL_SUCCESS) { |
|
2459 |
+ //cli_altnmsg("returned ac_special_altstr %d\n", ret); |
|
2460 |
+ error = ret; |
|
2461 |
+ break; |
|
2462 |
+ } |
|
2463 |
+ } |
|
2464 |
+ } |
|
2465 |
+ |
|
2466 |
+ if(start) |
|
2467 |
+ cli_strlcat(hexnew, start, hexnewsz); |
|
2468 |
+ |
|
2469 |
+ hex = hexnew; |
|
2470 |
+ free(hexcpy); |
|
2471 |
+ |
|
2472 |
+ if(error) { |
|
2473 |
+ free(hex); |
|
2474 |
+ if(new->special) { |
|
2475 |
+ mpool_ac_free_special(root->mempool, new); |
|
2476 |
+ } |
|
2477 |
+ mpool_free(root->mempool, new); |
|
2478 |
+ return error; |
|
2479 |
+ } |
|
2480 | 2480 |
} |
2481 | 2481 |
|
2482 | 2482 |
new->pattern = cli_mpool_hex2ui(root->mempool, hex ? hex : hexsig); |
... | ... |
@@ -2495,11 +2495,11 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex |
2495 | 2495 |
new->sigopts = sigopts; |
2496 | 2496 |
/* setting nocase match; TODO - move nocase to the pattern and verifier */ |
2497 | 2497 |
if (sigopts & ACPATT_OPTION_NOCASE) { |
2498 |
- for (i = 0; i < new->length; ++i) |
|
2499 |
- if ((new->pattern[i] & CLI_MATCH_METADATA) == CLI_MATCH_CHAR) { |
|
2500 |
- new->pattern[i] = cli_nocase(new->pattern[i] & 0xff); |
|
2501 |
- new->pattern[i] += CLI_MATCH_NOCASE; |
|
2502 |
- } |
|
2498 |
+ for (i = 0; i < new->length; ++i) |
|
2499 |
+ if ((new->pattern[i] & CLI_MATCH_METADATA) == CLI_MATCH_CHAR) { |
|
2500 |
+ new->pattern[i] = cli_nocase(new->pattern[i] & 0xff); |
|
2501 |
+ new->pattern[i] += CLI_MATCH_NOCASE; |
|
2502 |
+ } |
|
2503 | 2503 |
} |
2504 | 2504 |
|
2505 | 2505 |
if (root->filter) { //TODO - fix filters for nocase state, also fix for sigtool as well |