44 #define PARSE_REGEX "^\\s*([!])?\\s*([0-9]{1,9}+)\\s*$"
52 static void DetectWindowRegisterTests(
void);
116 pcre2_match_data *match = NULL;
118 if (ret < 1 || ret > 3) {
119 SCLogError(
"pcre_exec parse error, ret %" PRId32
", string %s", ret, windowstr);
128 char copy_str[128] =
"";
129 pcre2len =
sizeof(copy_str);
132 SCLogError(
"pcre2_substring_copy_bynumber failed");
137 if (copy_str[0] ==
'!')
143 pcre2len =
sizeof(copy_str);
144 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)copy_str, &pcre2len);
146 SCLogError(
"pcre2_substring_copy_bynumber failed");
158 pcre2_match_data_free(match);
163 pcre2_match_data_free(match);
186 wd = DetectWindowParse(
de_ctx, windowstr);
187 if (wd == NULL)
goto error;
205 if (sm != NULL)
SCFree(sm);
227 static int DetectWindowTestParse01 (
void)
231 wd = DetectWindowParse(NULL,
"35402");
232 if (wd != NULL &&wd->
size==35402) {
243 static int DetectWindowTestParse02 (
void)
247 wd = DetectWindowParse(NULL,
"!35402");
252 printf(
"expected wd->negated=1 and wd->size=35402\n");
263 static int DetectWindowTestParse03 (
void)
267 wd = DetectWindowParse(NULL,
"");
271 printf(
"expected a NULL pointer (It was an empty string)\n");
281 static int DetectWindowTestParse04 (
void)
285 wd = DetectWindowParse(NULL,
"1235402");
287 printf(
"expected a NULL pointer (It was exceeding the MAX window size)\n");
298 static int DetectWindowTestPacket01 (
void)
301 uint8_t *buf = (uint8_t *)
"Hi all!";
302 uint16_t buflen = strlen((
char *)buf);
308 if (p[0] == NULL || p[1] == NULL ||p[2] == NULL)
312 p[0]->
tcph->th_win = htons(40);
315 p[1]->
tcph->th_win = htons(41);
318 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing window 1\"; window:40; sid:1;)";
319 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing window 2\"; window:41; sid:2;)";
321 uint32_t sid[2] = {1, 2};
340 void DetectWindowRegisterTests(
void)
342 UtRegisterTest(
"DetectWindowTestParse01", DetectWindowTestParse01);
343 UtRegisterTest(
"DetectWindowTestParse02", DetectWindowTestParse02);
344 UtRegisterTest(
"DetectWindowTestParse03", DetectWindowTestParse03);
345 UtRegisterTest(
"DetectWindowTestParse04", DetectWindowTestParse04);
346 UtRegisterTest(
"DetectWindowTestPacket01", DetectWindowTestPacket01);