Browse code

ac_special: tracks both the min and max lengths

Kevin Lin authored on 2015/07/02 05:53:07
Showing 2 changed files
... ...
@@ -154,7 +154,7 @@ static inline int insert_list(struct cli_matcher *root, struct cli_ac_patt *patt
154 154
                             }
155 155
 
156 156
                             for(j = 0; j < a1->num; j++) {
157
-                                if(memcmp((a1->alt).f_str[j], (a2->alt).f_str[j], a1->len))
157
+                                if(memcmp((a1->alt).f_str[j], (a2->alt).f_str[j], a1->len[0]))
158 158
                                     break;
159 159
                             }
160 160
 
... ...
@@ -959,14 +959,14 @@ inline static int ac_findmatch_special(const unsigned char *buffer, uint32_t off
959 959
         break;
960 960
 
961 961
     case AC_SPECIAL_ALT_STR_FIXED: /* fixed length multi-byte */
962
-        if (bp + special->len > length)
962
+        if (bp + special->len[0] > length)
963 963
             break;
964 964
 
965
-        match *= special->len;
965
+        match *= special->len[0];
966 966
         for (j = 0; j < special->num; j++) {
967
-            cmp = memcmp(&buffer[bp], (special->alt).f_str[j], special->len);
967
+            cmp = memcmp(&buffer[bp], (special->alt).f_str[j], special->len[0]);
968 968
             if (cmp == 0) {
969
-                match = (!special->negative) * special->len;
969
+                match = (!special->negative) * special->len[0];
970 970
                 break;
971 971
             } else if (cmp < 0)
972 972
                 break;
... ...
@@ -2114,6 +2114,10 @@ inline static int ac_addspecial_add_alt_node(const char *subexpr, uint8_t sigopt
2114 2114
 
2115 2115
     *prev = newnode;
2116 2116
     newnode->next = ins;
2117
+    if ((special->num == 0) || (newnode->len < special->len[0]))
2118
+        special->len[0] = newnode->len;
2119
+    if ((special->num == 0) || (newnode->len > special->len[1]))
2120
+        special->len[1] = newnode->len;
2117 2121
     special->num++;
2118 2122
     return CL_SUCCESS;
2119 2123
 }
... ...
@@ -2250,7 +2254,7 @@ inline static int ac_special_altstr(const char *hexpr, uint8_t sigopts, struct c
2250 2250
 
2251 2251
     if (!sigopts && fixed) {
2252 2252
         special->num = 0;
2253
-        special->len = slen / 2;
2253
+        special->len[0] = special->len[1] = slen / 2;
2254 2254
         /* single-bytes are len 2 in hex */
2255 2255
         if (slen == 2) {
2256 2256
             special->type = AC_SPECIAL_ALT_CHAR;
... ...
@@ -71,7 +71,6 @@ struct cli_ac_data {
71 71
 
72 72
 struct cli_alt_node {
73 73
     uint16_t *str;
74
-    //unsigned char *str;
75 74
     uint16_t len;
76 75
     uint8_t unique;
77 76
     struct cli_alt_node *next;
... ...
@@ -79,13 +78,11 @@ struct cli_alt_node {
79 79
 
80 80
 struct cli_ac_special {
81 81
     union {
82
-        //uint16_t *byte;
83
-        //uint16_t **f_str;
84 82
         unsigned char *byte;
85 83
         unsigned char **f_str;
86 84
         struct cli_alt_node *v_str;
87 85
     } alt;
88
-    uint16_t len, num;
86
+    uint16_t len[2], num; /* 0=MIN, 1=MAX */
89 87
     uint16_t type, negative;
90 88
 };
91 89