52 static void DetectUrilenRegisterTests (
void);
54 static int g_http_uri_buffer_id = 0;
55 static int g_http_raw_uri_buffer_id = 0;
86 static DetectUrilenData *DetectUrilenParse (
const char *urilenstr)
88 return rs_detect_urilen_parse(urilenstr);
104 DetectUrilenData *urilend = NULL;
110 urilend = DetectUrilenParse(urilenstr);
117 sm->
ctx = (
void *)urilend;
119 if (urilend->raw_buffer)
127 DetectUrilenFree(
de_ctx, urilend);
141 DetectUrilenData *urilend = (DetectUrilenData *)ptr;
142 rs_detect_urilen_free(urilend);
150 uint16_t high = UINT16_MAX;
154 for ( ; sm != NULL; sm = sm->
next) {
158 DetectUrilenData *dd = (DetectUrilenData *)sm->
ctx;
160 switch (dd->du16.mode) {
162 if (dd->du16.arg1 < UINT16_MAX) {
163 high = dd->du16.arg1 + 1;
169 high = dd->du16.arg1;
172 if (dd->du16.arg2 < UINT16_MAX) {
173 high = dd->du16.arg2 + 1;
188 if (!found || high == UINT16_MAX)
194 for ( ; sm != NULL; sm = sm->
next) {
206 SCLogDebug(
"updated %u, content %u to have depth %u "
207 "because of urilen.", s->
id, cd->
id, cd->
depth);
215 for ( ; sm != NULL; sm = sm->
next) {
225 *sigerror =
"depth or urilen smaller than content len";
227 "than content len %u",
245 static int DetectUrilenParseTest01(
void)
248 DetectUrilenData *urilend = NULL;
250 urilend = DetectUrilenParse(
"10");
251 if (urilend != NULL) {
252 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_EQ &&
253 !urilend->raw_buffer)
256 DetectUrilenFree(NULL, urilend);
262 static int DetectUrilenParseTest02(
void)
265 DetectUrilenData *urilend = NULL;
267 urilend = DetectUrilenParse(
" < 10 ");
268 if (urilend != NULL) {
269 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT &&
270 !urilend->raw_buffer)
273 DetectUrilenFree(NULL, urilend);
279 static int DetectUrilenParseTest03(
void)
282 DetectUrilenData *urilend = NULL;
284 urilend = DetectUrilenParse(
" > 10 ");
285 if (urilend != NULL) {
286 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT &&
287 !urilend->raw_buffer)
290 DetectUrilenFree(NULL, urilend);
296 static int DetectUrilenParseTest04(
void)
299 DetectUrilenData *urilend = NULL;
301 urilend = DetectUrilenParse(
" 5 <> 10 ");
302 if (urilend != NULL) {
303 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
307 DetectUrilenFree(NULL, urilend);
313 static int DetectUrilenParseTest05(
void)
316 DetectUrilenData *urilend = NULL;
318 urilend = DetectUrilenParse(
"5<>10,norm");
319 if (urilend != NULL) {
320 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
324 DetectUrilenFree(NULL, urilend);
330 static int DetectUrilenParseTest06(
void)
333 DetectUrilenData *urilend = NULL;
335 urilend = DetectUrilenParse(
"5<>10,raw");
336 if (urilend != NULL) {
337 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
341 DetectUrilenFree(NULL, urilend);
347 static int DetectUrilenParseTest07(
void)
350 DetectUrilenData *urilend = NULL;
352 urilend = DetectUrilenParse(
">10, norm ");
353 if (urilend != NULL) {
354 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT &&
355 !urilend->raw_buffer)
358 DetectUrilenFree(NULL, urilend);
364 static int DetectUrilenParseTest08(
void)
367 DetectUrilenData *urilend = NULL;
369 urilend = DetectUrilenParse(
"<10, norm ");
370 if (urilend != NULL) {
371 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT &&
372 !urilend->raw_buffer)
375 DetectUrilenFree(NULL, urilend);
381 static int DetectUrilenParseTest09(
void)
384 DetectUrilenData *urilend = NULL;
386 urilend = DetectUrilenParse(
">10, raw ");
387 if (urilend != NULL) {
388 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT && urilend->raw_buffer)
391 DetectUrilenFree(NULL, urilend);
397 static int DetectUrilenParseTest10(
void)
400 DetectUrilenData *urilend = NULL;
402 urilend = DetectUrilenParse(
"<10, raw ");
403 if (urilend != NULL) {
404 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT && urilend->raw_buffer)
407 DetectUrilenFree(NULL, urilend);
419 DetectUrilenData **urilend,
const char *
str)
427 if (snprintf(fullstr, 1024,
"alert ip any any -> any any (msg:\"Urilen "
428 "test\"; urilen:%s; sid:1;)",
str) >= 1024) {
440 if ((*de_ctx)->sig_list == NULL) {
444 *sig = (*de_ctx)->sig_list;
446 *urilend = DetectUrilenParse(
str);
461 static int DetectUrilenSetpTest01(
void)
464 DetectUrilenData *urilend = NULL;
469 res = DetectUrilenInitTest(&
de_ctx, &sig, &urilend,
"1 <> 2 ");
477 if (urilend != NULL) {
478 if (urilend->du16.arg1 == 1 && urilend->du16.arg2 == 2 &&
485 DetectUrilenFree(NULL, urilend);
494 static int DetectUrilenSigTest01(
void)
498 uint8_t httpbuf1[] =
"POST /suricata HTTP/1.0\r\n"
499 "Host: foo.bar.tld\r\n"
501 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
509 memset(&th_v, 0,
sizeof(th_v));
510 memset(&f, 0,
sizeof(f));
511 memset(&ssn, 0,
sizeof(ssn));
517 f.
proto = IPPROTO_TCP;
536 "alert tcp any any -> any any "
537 "(msg:\"Testing urilen\"; "
538 "urilen: <5; sid:1;)");
544 "alert tcp any any -> any any "
545 "(msg:\"Testing http_method\"; "
546 "urilen: >5; sid:2;)");
557 SCLogDebug(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
562 if (htp_state == NULL) {
570 printf(
"sid 1 alerted, but should not have: \n");
574 printf(
"sid 2 did not alerted, but should have: \n");
596 void DetectUrilenRegisterTests(
void)
598 UtRegisterTest(
"DetectUrilenParseTest01", DetectUrilenParseTest01);
599 UtRegisterTest(
"DetectUrilenParseTest02", DetectUrilenParseTest02);
600 UtRegisterTest(
"DetectUrilenParseTest03", DetectUrilenParseTest03);
601 UtRegisterTest(
"DetectUrilenParseTest04", DetectUrilenParseTest04);
602 UtRegisterTest(
"DetectUrilenParseTest05", DetectUrilenParseTest05);
603 UtRegisterTest(
"DetectUrilenParseTest06", DetectUrilenParseTest06);
604 UtRegisterTest(
"DetectUrilenParseTest07", DetectUrilenParseTest07);
605 UtRegisterTest(
"DetectUrilenParseTest08", DetectUrilenParseTest08);
606 UtRegisterTest(
"DetectUrilenParseTest09", DetectUrilenParseTest09);
607 UtRegisterTest(
"DetectUrilenParseTest10", DetectUrilenParseTest10);