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);
154 uint16_t high = UINT16_MAX;
161 DetectUrilenData *dd = (DetectUrilenData *)sm->
ctx;
163 switch (dd->du16.mode) {
165 if (dd->du16.arg1 < UINT16_MAX) {
166 high = dd->du16.arg1 + 1;
172 high = dd->du16.arg1;
175 if (dd->du16.arg2 < UINT16_MAX) {
176 high = dd->du16.arg2 + 1;
191 if (!found || high == UINT16_MAX)
208 SCLogDebug(
"updated %u, content %u to have depth %u "
209 "because of urilen.",
231 *sigerror =
"depth or urilen smaller than content len";
233 "than content len %u",
252 static int DetectUrilenParseTest01(
void)
255 DetectUrilenData *urilend = NULL;
257 urilend = DetectUrilenParse(
"10");
258 if (urilend != NULL) {
259 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_EQ &&
260 !urilend->raw_buffer)
263 DetectUrilenFree(NULL, urilend);
269 static int DetectUrilenParseTest02(
void)
272 DetectUrilenData *urilend = NULL;
274 urilend = DetectUrilenParse(
" < 10 ");
275 if (urilend != NULL) {
276 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT &&
277 !urilend->raw_buffer)
280 DetectUrilenFree(NULL, urilend);
286 static int DetectUrilenParseTest03(
void)
289 DetectUrilenData *urilend = NULL;
291 urilend = DetectUrilenParse(
" > 10 ");
292 if (urilend != NULL) {
293 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT &&
294 !urilend->raw_buffer)
297 DetectUrilenFree(NULL, urilend);
303 static int DetectUrilenParseTest04(
void)
306 DetectUrilenData *urilend = NULL;
308 urilend = DetectUrilenParse(
" 5 <> 10 ");
309 if (urilend != NULL) {
310 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
314 DetectUrilenFree(NULL, urilend);
320 static int DetectUrilenParseTest05(
void)
323 DetectUrilenData *urilend = NULL;
325 urilend = DetectUrilenParse(
"5<>10,norm");
326 if (urilend != NULL) {
327 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
331 DetectUrilenFree(NULL, urilend);
337 static int DetectUrilenParseTest06(
void)
340 DetectUrilenData *urilend = NULL;
342 urilend = DetectUrilenParse(
"5<>10,raw");
343 if (urilend != NULL) {
344 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
348 DetectUrilenFree(NULL, urilend);
354 static int DetectUrilenParseTest07(
void)
357 DetectUrilenData *urilend = NULL;
359 urilend = DetectUrilenParse(
">10, norm ");
360 if (urilend != NULL) {
361 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT &&
362 !urilend->raw_buffer)
365 DetectUrilenFree(NULL, urilend);
371 static int DetectUrilenParseTest08(
void)
374 DetectUrilenData *urilend = NULL;
376 urilend = DetectUrilenParse(
"<10, norm ");
377 if (urilend != NULL) {
378 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT &&
379 !urilend->raw_buffer)
382 DetectUrilenFree(NULL, urilend);
388 static int DetectUrilenParseTest09(
void)
391 DetectUrilenData *urilend = NULL;
393 urilend = DetectUrilenParse(
">10, raw ");
394 if (urilend != NULL) {
395 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT && urilend->raw_buffer)
398 DetectUrilenFree(NULL, urilend);
404 static int DetectUrilenParseTest10(
void)
407 DetectUrilenData *urilend = NULL;
409 urilend = DetectUrilenParse(
"<10, raw ");
410 if (urilend != NULL) {
411 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT && urilend->raw_buffer)
414 DetectUrilenFree(NULL, urilend);
426 DetectUrilenData **urilend,
const char *
str)
434 if (snprintf(fullstr, 1024,
"alert ip any any -> any any (msg:\"Urilen "
435 "test\"; urilen:%s; sid:1;)",
str) >= 1024) {
447 if ((*de_ctx)->sig_list == NULL) {
451 *sig = (*de_ctx)->sig_list;
453 *urilend = DetectUrilenParse(
str);
468 static int DetectUrilenSetpTest01(
void)
471 DetectUrilenData *urilend = NULL;
476 res = DetectUrilenInitTest(&
de_ctx, &sig, &urilend,
"1 <> 2 ");
484 if (urilend != NULL) {
485 if (urilend->du16.arg1 == 1 && urilend->du16.arg2 == 2 &&
492 DetectUrilenFree(NULL, urilend);
501 static int DetectUrilenSigTest01(
void)
505 uint8_t httpbuf1[] =
"POST /suricata HTTP/1.0\r\n"
506 "Host: foo.bar.tld\r\n"
508 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
516 memset(&th_v, 0,
sizeof(th_v));
517 memset(&f, 0,
sizeof(f));
518 memset(&ssn, 0,
sizeof(ssn));
524 f.
proto = IPPROTO_TCP;
543 "alert tcp any any -> any any "
544 "(msg:\"Testing urilen\"; "
545 "urilen: <5; sid:1;)");
551 "alert tcp any any -> any any "
552 "(msg:\"Testing http_method\"; "
553 "urilen: >5; sid:2;)");
564 SCLogDebug(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
569 if (htp_state == NULL) {
577 printf(
"sid 1 alerted, but should not have: \n");
581 printf(
"sid 2 did not alerted, but should have: \n");
603 void DetectUrilenRegisterTests(
void)
605 UtRegisterTest(
"DetectUrilenParseTest01", DetectUrilenParseTest01);
606 UtRegisterTest(
"DetectUrilenParseTest02", DetectUrilenParseTest02);
607 UtRegisterTest(
"DetectUrilenParseTest03", DetectUrilenParseTest03);
608 UtRegisterTest(
"DetectUrilenParseTest04", DetectUrilenParseTest04);
609 UtRegisterTest(
"DetectUrilenParseTest05", DetectUrilenParseTest05);
610 UtRegisterTest(
"DetectUrilenParseTest06", DetectUrilenParseTest06);
611 UtRegisterTest(
"DetectUrilenParseTest07", DetectUrilenParseTest07);
612 UtRegisterTest(
"DetectUrilenParseTest08", DetectUrilenParseTest08);
613 UtRegisterTest(
"DetectUrilenParseTest09", DetectUrilenParseTest09);
614 UtRegisterTest(
"DetectUrilenParseTest10", DetectUrilenParseTest10);