44 #define PARSE_REGEX "^\\s*([!])?\\s*([0-9]{1,9}+)\\s*$"
52 static void DetectWindowRegisterTests(
void);
113 int ret = 0, res = 0;
117 if (ret < 1 || ret > 3) {
118 SCLogError(
"pcre_exec parse error, ret %" PRId32
", string %s", ret, windowstr);
127 char copy_str[128] =
"";
128 pcre2len =
sizeof(copy_str);
131 SCLogError(
"pcre2_substring_copy_bynumber failed");
136 if (copy_str[0] ==
'!')
142 pcre2len =
sizeof(copy_str);
143 res = pcre2_substring_copy_bynumber(
144 parse_regex.
match, 2, (PCRE2_UCHAR8 *)copy_str, &pcre2len);
146 SCLogError(
"pcre2_substring_copy_bynumber failed");
182 wd = DetectWindowParse(
de_ctx, windowstr);
183 if (wd == NULL)
goto error;
201 if (sm != NULL)
SCFree(sm);
223 static int DetectWindowTestParse01 (
void)
227 wd = DetectWindowParse(NULL,
"35402");
228 if (wd != NULL &&wd->
size==35402) {
239 static int DetectWindowTestParse02 (
void)
243 wd = DetectWindowParse(NULL,
"!35402");
248 printf(
"expected wd->negated=1 and wd->size=35402\n");
259 static int DetectWindowTestParse03 (
void)
263 wd = DetectWindowParse(NULL,
"");
267 printf(
"expected a NULL pointer (It was an empty string)\n");
277 static int DetectWindowTestParse04 (
void)
281 wd = DetectWindowParse(NULL,
"1235402");
283 printf(
"expected a NULL pointer (It was exceeding the MAX window size)\n");
294 static int DetectWindowTestPacket01 (
void)
297 uint8_t *buf = (uint8_t *)
"Hi all!";
298 uint16_t buflen = strlen((
char *)buf);
304 if (p[0] == NULL || p[1] == NULL ||p[2] == NULL)
308 p[0]->
tcph->th_win = htons(40);
311 p[1]->
tcph->th_win = htons(41);
314 sigs[0]=
"alert tcp any any -> any any (msg:\"Testing window 1\"; window:40; sid:1;)";
315 sigs[1]=
"alert tcp any any -> any any (msg:\"Testing window 2\"; window:41; sid:2;)";
317 uint32_t sid[2] = {1, 2};
336 void DetectWindowRegisterTests(
void)
338 UtRegisterTest(
"DetectWindowTestParse01", DetectWindowTestParse01);
339 UtRegisterTest(
"DetectWindowTestParse02", DetectWindowTestParse02);
340 UtRegisterTest(
"DetectWindowTestParse03", DetectWindowTestParse03);
341 UtRegisterTest(
"DetectWindowTestParse04", DetectWindowTestParse04);
342 UtRegisterTest(
"DetectWindowTestPacket01", DetectWindowTestPacket01);