45 #define PARSE_REGEX "^\\s*([!])?\\s*([0-9]{1,9}+)\\s*$"
53 static void DetectWindowRegisterTests(
void);
114 int ret = 0,
res = 0;
118 if (ret < 1 || ret > 3) {
128 char copy_str[128] =
"";
129 pcre2len =
sizeof(copy_str);
137 if (copy_str[0] ==
'!')
143 pcre2len =
sizeof(copy_str);
144 res = pcre2_substring_copy_bynumber(
145 parse_regex.
match, 2, (PCRE2_UCHAR8 *)copy_str, &pcre2len);
183 wd = DetectWindowParse(
de_ctx, windowstr);
184 if (wd == NULL)
goto error;
202 if (sm != NULL)
SCFree(sm);
224 static int DetectWindowTestParse01 (
void)
228 wd = DetectWindowParse(NULL,
"35402");
229 if (wd != NULL &&wd->
size==35402) {
240 static int DetectWindowTestParse02 (
void)
244 wd = DetectWindowParse(NULL,
"!35402");
249 printf(
"expected wd->negated=1 and wd->size=35402\n");
260 static int DetectWindowTestParse03 (
void)
264 wd = DetectWindowParse(NULL,
"");
268 printf(
"expected a NULL pointer (It was an empty string)\n");
278 static int DetectWindowTestParse04 (
void)
282 wd = DetectWindowParse(NULL,
"1235402");
284 printf(
"expected a NULL pointer (It was exceeding the MAX window size)\n");
295 static int DetectWindowTestPacket01 (
void)
298 uint8_t *buf = (uint8_t *)
"Hi all!";
299 uint16_t buflen = strlen((
char *)buf);
305 if (p[0] == NULL || p[1] == NULL ||p[2] == NULL)
309 p[0]->
tcph->th_win = htons(40);
312 p[1]->
tcph->th_win = htons(41);
315 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing window 1\"; window:40; sid:1;)";
316 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing window 2\"; window:41; sid:2;)";
318 uint32_t sid[2] = {1, 2};
337 void DetectWindowRegisterTests(
void)
339 UtRegisterTest(
"DetectWindowTestParse01", DetectWindowTestParse01);
340 UtRegisterTest(
"DetectWindowTestParse02", DetectWindowTestParse02);
341 UtRegisterTest(
"DetectWindowTestParse03", DetectWindowTestParse03);
342 UtRegisterTest(
"DetectWindowTestParse04", DetectWindowTestParse04);
343 UtRegisterTest(
"DetectWindowTestPacket01", DetectWindowTestPacket01);