]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcre: print filename and line number for JIT warning.
authorVictor Julien <victor@inliniac.net>
Tue, 22 May 2012 10:46:19 +0000 (12:46 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 22 May 2012 10:46:19 +0000 (12:46 +0200)
src/detect-pcre.c
src/detect.c
src/detect.h

index 36209eee3296cb8aa8dd76ed9f13a837f9ec3428..a5391404d8dd2e9075bd244f62c03f4df76b4175 100644 (file)
@@ -727,7 +727,7 @@ int DetectPcreMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Packet *p,
     SCReturnInt(r);
 }
 
-DetectPcreData *DetectPcreParse (char *regexstr)
+DetectPcreData *DetectPcreParse (DetectEngineCtx *de_ctx, char *regexstr)
 {
     int ec;
     const char *eb;
@@ -946,7 +946,12 @@ DetectPcreData *DetectPcreParse (char *regexstr)
     int jit = 0;
     ret = pcre_fullinfo(pd->re, pd->sd, PCRE_INFO_JIT, &jit);
     if (ret != 0 || jit != 1) {
-        SCLogWarning(SC_ERR_PCRE_STUDY, "PCRE JIT compiler does not support: %s", regexstr);
+        /* warning, so we won't print the sig after this. Adding
+         * file and line to the message so the admin can figure
+         * out what sig this is about */
+        SCLogWarning(SC_ERR_PCRE_STUDY, "PCRE JIT compiler does not support: %s. "
+                "Falling back to regular PCRE handling (%s:%d)",
+                regexstr, de_ctx->rule_file, de_ctx->rule_line);
     }
 #else
     pd->sd = pcre_study(pd->re, 0, &eb);
@@ -1067,7 +1072,7 @@ static int DetectPcreSetup (DetectEngineCtx *de_ctx, Signature *s, char *regexst
     SigMatch *sm = NULL;
     SigMatch *prev_sm = NULL;
 
-    pd = DetectPcreParse(regexstr);
+    pd = DetectPcreParse(de_ctx, regexstr);
     if (pd == NULL)
         goto error;
 
@@ -1329,13 +1334,18 @@ static int DetectPcreParseTest01 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/blah/7";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd != NULL) {
         printf("expected NULL: got %p", pd);
         result = 0;
         DetectPcreFree(pd);
     }
+
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
@@ -1346,13 +1356,17 @@ static int DetectPcreParseTest02 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/blah/Ui$";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd != NULL) {
         printf("expected NULL: got %p", pd);
         result = 0;
         DetectPcreFree(pd);
     }
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
@@ -1363,13 +1377,17 @@ static int DetectPcreParseTest03 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/blah/UZi";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd != NULL) {
         printf("expected NULL: got %p", pd);
         result = 0;
         DetectPcreFree(pd);
     }
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
@@ -1380,14 +1398,18 @@ static int DetectPcreParseTest04 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/b\\\"lah/i";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd == NULL) {
         printf("expected %p: got NULL", pd);
         result = 0;
     }
 
     DetectPcreFree(pd);
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
@@ -1398,14 +1420,18 @@ static int DetectPcreParseTest05 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/b(l|a)h/";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd == NULL) {
         printf("expected %p: got NULL", pd);
         result = 0;
     }
 
     DetectPcreFree(pd);
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
@@ -1416,14 +1442,18 @@ static int DetectPcreParseTest06 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/b(l|a)h/smi";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd == NULL) {
         printf("expected %p: got NULL", pd);
         result = 0;
     }
 
     DetectPcreFree(pd);
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
@@ -1434,14 +1464,18 @@ static int DetectPcreParseTest07 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/blah/Ui";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd == NULL) {
         printf("expected %p: got NULL", pd);
         result = 0;
     }
 
     DetectPcreFree(pd);
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
@@ -1452,14 +1486,18 @@ static int DetectPcreParseTest08 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/b(l|a)h/O";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd == NULL) {
         printf("expected %p: got NULL", pd);
         result = 0;
     }
 
     DetectPcreFree(pd);
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
@@ -1471,14 +1509,18 @@ static int DetectPcreParseTest09 (void) {
     int result = 1;
     DetectPcreData *pd = NULL;
     char *teststring = "/lala\\\\/";
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        return 0;
 
-    pd = DetectPcreParse(teststring);
+    pd = DetectPcreParse(de_ctx, teststring);
     if (pd == NULL) {
         printf("expected %p: got NULL", pd);
         result = 0;
     }
 
     DetectPcreFree(pd);
+    DetectEngineCtxFree(de_ctx);
     return result;
 }
 
index 3c109f7b52e68ac1004b54bd26fe3c5ce76b0347..ad60a254f1a02f081301b59aeb8577587a715c9a 100644 (file)
@@ -513,6 +513,9 @@ int DetectLoadSigFile(DetectEngineCtx *de_ctx, char *sig_file, int *sigs_tot) {
         /* Reset offset. */
         offset = 0;
 
+        de_ctx->rule_file = sig_file;
+        de_ctx->rule_line = lineno - multiline;
+
         sig = DetectEngineAppendSig(de_ctx, line);
         (*sigs_tot)++;
         if (sig != NULL) {
index 06fc7def1d92fd7759fe42d427bfbc455e626396..ed5b084e1a85c48b35d44cd4498fa982d2203050 100644 (file)
@@ -649,6 +649,10 @@ typedef struct DetectEngineCtx_ {
     /** sgh for signatures that match against invalid packets. In those cases
      *  we can't lookup by proto, address, port as we don't have these */
     struct SigGroupHead_ *decoder_event_sgh;
+
+    /** Store rule file and line so that parsers can use them in errors. */
+    char *rule_file;
+    int rule_line;
 } DetectEngineCtx;
 
 /* Engine groups profiles (low, medium, high, custom) */