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;
109 urilend = DetectUrilenParse(urilenstr);
113 if (urilend->raw_buffer) {
115 g_http_raw_uri_buffer_id) == NULL) {
120 g_http_uri_buffer_id) == NULL) {
128 DetectUrilenFree(
de_ctx, urilend);
142 DetectUrilenData *urilend = (DetectUrilenData *)ptr;
143 rs_detect_urilen_free(urilend);
155 uint16_t high = UINT16_MAX;
162 DetectUrilenData *dd = (DetectUrilenData *)sm->ctx;
164 switch (dd->du16.mode) {
166 if (dd->du16.arg1 < UINT16_MAX) {
167 high = dd->du16.arg1 + 1;
173 high = dd->du16.arg1;
176 if (dd->du16.arg2 < UINT16_MAX) {
177 high = dd->du16.arg2 + 1;
192 if (!found || high == UINT16_MAX)
209 SCLogDebug(
"updated %u, content %u to have depth %u "
210 "because of urilen.",
233 *sigerror =
"depth or urilen smaller than content len";
235 "than content len %u",
254 static int DetectUrilenParseTest01(
void)
257 DetectUrilenData *urilend = NULL;
259 urilend = DetectUrilenParse(
"10");
260 if (urilend != NULL) {
261 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_EQ &&
262 !urilend->raw_buffer)
265 DetectUrilenFree(NULL, urilend);
271 static int DetectUrilenParseTest02(
void)
274 DetectUrilenData *urilend = NULL;
276 urilend = DetectUrilenParse(
" < 10 ");
277 if (urilend != NULL) {
278 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT &&
279 !urilend->raw_buffer)
282 DetectUrilenFree(NULL, urilend);
288 static int DetectUrilenParseTest03(
void)
291 DetectUrilenData *urilend = NULL;
293 urilend = DetectUrilenParse(
" > 10 ");
294 if (urilend != NULL) {
295 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT &&
296 !urilend->raw_buffer)
299 DetectUrilenFree(NULL, urilend);
305 static int DetectUrilenParseTest04(
void)
308 DetectUrilenData *urilend = NULL;
310 urilend = DetectUrilenParse(
" 5 <> 10 ");
311 if (urilend != NULL) {
312 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
316 DetectUrilenFree(NULL, urilend);
322 static int DetectUrilenParseTest05(
void)
325 DetectUrilenData *urilend = NULL;
327 urilend = DetectUrilenParse(
"5<>10,norm");
328 if (urilend != NULL) {
329 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
333 DetectUrilenFree(NULL, urilend);
339 static int DetectUrilenParseTest06(
void)
342 DetectUrilenData *urilend = NULL;
344 urilend = DetectUrilenParse(
"5<>10,raw");
345 if (urilend != NULL) {
346 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
350 DetectUrilenFree(NULL, urilend);
356 static int DetectUrilenParseTest07(
void)
359 DetectUrilenData *urilend = NULL;
361 urilend = DetectUrilenParse(
">10, norm ");
362 if (urilend != NULL) {
363 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT &&
364 !urilend->raw_buffer)
367 DetectUrilenFree(NULL, urilend);
373 static int DetectUrilenParseTest08(
void)
376 DetectUrilenData *urilend = NULL;
378 urilend = DetectUrilenParse(
"<10, norm ");
379 if (urilend != NULL) {
380 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT &&
381 !urilend->raw_buffer)
384 DetectUrilenFree(NULL, urilend);
390 static int DetectUrilenParseTest09(
void)
393 DetectUrilenData *urilend = NULL;
395 urilend = DetectUrilenParse(
">10, raw ");
396 if (urilend != NULL) {
397 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT && urilend->raw_buffer)
400 DetectUrilenFree(NULL, urilend);
406 static int DetectUrilenParseTest10(
void)
409 DetectUrilenData *urilend = NULL;
411 urilend = DetectUrilenParse(
"<10, raw ");
412 if (urilend != NULL) {
413 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT && urilend->raw_buffer)
416 DetectUrilenFree(NULL, urilend);
428 DetectUrilenData **urilend,
const char *
str)
436 if (snprintf(fullstr, 1024,
"alert ip any any -> any any (msg:\"Urilen "
437 "test\"; urilen:%s; sid:1;)",
str) >= 1024) {
449 if ((*de_ctx)->sig_list == NULL) {
453 *sig = (*de_ctx)->sig_list;
455 *urilend = DetectUrilenParse(
str);
470 static int DetectUrilenSetpTest01(
void)
473 DetectUrilenData *urilend = NULL;
478 res = DetectUrilenInitTest(&
de_ctx, &sig, &urilend,
"1 <> 2 ");
486 if (urilend != NULL) {
487 if (urilend->du16.arg1 == 1 && urilend->du16.arg2 == 2 &&
494 DetectUrilenFree(NULL, urilend);
503 static int DetectUrilenSigTest01(
void)
507 uint8_t httpbuf1[] =
"POST /suricata HTTP/1.0\r\n"
508 "Host: foo.bar.tld\r\n"
510 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
518 memset(&th_v, 0,
sizeof(th_v));
519 memset(&f, 0,
sizeof(f));
520 memset(&ssn, 0,
sizeof(ssn));
526 f.
proto = IPPROTO_TCP;
545 "alert tcp any any -> any any "
546 "(msg:\"Testing urilen\"; "
547 "urilen: <5; sid:1;)");
553 "alert tcp any any -> any any "
554 "(msg:\"Testing http_method\"; "
555 "urilen: >5; sid:2;)");
566 SCLogDebug(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
571 if (htp_state == NULL) {
579 printf(
"sid 1 alerted, but should not have: \n");
583 printf(
"sid 2 did not alerted, but should have: \n");
605 void DetectUrilenRegisterTests(
void)
607 UtRegisterTest(
"DetectUrilenParseTest01", DetectUrilenParseTest01);
608 UtRegisterTest(
"DetectUrilenParseTest02", DetectUrilenParseTest02);
609 UtRegisterTest(
"DetectUrilenParseTest03", DetectUrilenParseTest03);
610 UtRegisterTest(
"DetectUrilenParseTest04", DetectUrilenParseTest04);
611 UtRegisterTest(
"DetectUrilenParseTest05", DetectUrilenParseTest05);
612 UtRegisterTest(
"DetectUrilenParseTest06", DetectUrilenParseTest06);
613 UtRegisterTest(
"DetectUrilenParseTest07", DetectUrilenParseTest07);
614 UtRegisterTest(
"DetectUrilenParseTest08", DetectUrilenParseTest08);
615 UtRegisterTest(
"DetectUrilenParseTest09", DetectUrilenParseTest09);
616 UtRegisterTest(
"DetectUrilenParseTest10", DetectUrilenParseTest10);