]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Check replist is not NULL inline before doing any processing.
authorKen Steele <ken@tilera.com>
Fri, 17 Oct 2014 15:42:48 +0000 (11:42 -0400)
committerVictor Julien <victor@inliniac.net>
Mon, 20 Oct 2014 06:05:25 +0000 (08:05 +0200)
The replist is often NULL, so it is worth checking that case before making
the function call do perform work on the list.

src/detect-replace.c
src/detect-replace.h
src/detect.c

index c2587d8e5c6967858b7ae234b38b0f8aa1b8175c..6031c31184f65c01d18106069bff0c8ab6470806 100644 (file)
@@ -174,13 +174,10 @@ DetectReplaceList * DetectReplaceAddToList(DetectReplaceList *replist, uint8_t *
 }
 
 
-void DetectReplaceExecute(Packet *p, DetectReplaceList *replist)
+void DetectReplaceExecuteInternal(Packet *p, DetectReplaceList *replist)
 {
     DetectReplaceList *tlist = NULL;
 
-    if (p == NULL)
-        return;
-
     SCLogDebug("replace: Executing match");
     while(replist) {
         memcpy(replist->found, replist->cd->replace, replist->cd->replace_len);
@@ -194,7 +191,7 @@ void DetectReplaceExecute(Packet *p, DetectReplaceList *replist)
 }
 
 
-void DetectReplaceFree(DetectReplaceList *replist)
+void DetectReplaceFreeInternal(DetectReplaceList *replist)
 {
     DetectReplaceList *tlist = NULL;
     while(replist) {
index f7b7c214d296b5bda8f14ecddab14efc0d432dd1..020f73c45e99d7c8e3a083f6ad3c009d67f066cf 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Open Information Security Foundation
+/* Copyright (C) 2011-2014 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
 #define __DETECT_REPLACE_H__
 
 DetectReplaceList * DetectReplaceAddToList(DetectReplaceList *replist, uint8_t *found, DetectContentData *cd);
-void DetectReplaceExecute(Packet *p, DetectReplaceList *replist);
-void DetectReplaceFree(DetectReplaceList *replist);
+
+/* Internal functions are only called via the inline functions below. */
+void DetectReplaceExecuteInternal(Packet *p, DetectReplaceList *replist);
+void DetectReplaceFreeInternal(DetectReplaceList *replist);
+
+static inline void DetectReplaceExecute(Packet *p, DetectEngineThreadCtx *det_ctx)
+{
+    if (p == NULL || det_ctx->replist == NULL)
+        return;
+    DetectReplaceExecuteInternal(p, det_ctx->replist);
+    det_ctx->replist = NULL;
+}
+
+static inline void DetectReplaceFree(DetectEngineThreadCtx *det_ctx)
+{
+    if (det_ctx->replist) {
+        DetectReplaceFreeInternal(det_ctx->replist);
+        det_ctx->replist = NULL;
+    }
+}
+
 void DetectReplaceRegister (void);
 
 #endif
index 2fe453c3dae96c6dd41b5635f8e60acd18276ef6..e8950a9707508274bf3863ea3b494bc3fb5097b2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2014 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -617,8 +617,7 @@ int SigMatchSignaturesRunPostMatch(ThreadVars *tv,
         }
     }
 
-    DetectReplaceExecute(p, det_ctx->replist);
-    det_ctx->replist = NULL;
+    DetectReplaceExecute(p, det_ctx);
 
     if (s->flags & SIG_FLAG_FILESTORE)
         DetectFilestorePostMatch(tv, det_ctx, p, s);
@@ -1564,8 +1563,7 @@ int SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineTh
         alerts++;
 next:
         DetectFlowvarProcessList(det_ctx, pflow);
-        DetectReplaceFree(det_ctx->replist);
-        det_ctx->replist = NULL;
+        DetectReplaceFree(det_ctx);
         RULE_PROFILING_END(det_ctx, s, smatch, p);
 
         det_ctx->flags = 0;