From: Ken Steele Date: Fri, 17 Oct 2014 15:42:48 +0000 (-0400) Subject: Check replist is not NULL inline before doing any processing. X-Git-Tag: suricata-2.1beta2~76 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=60c46170b047880ace06d2e57eac2f9cc4cbb624;p=thirdparty%2Fsuricata.git Check replist is not NULL inline before doing any processing. The replist is often NULL, so it is worth checking that case before making the function call do perform work on the list. --- diff --git a/src/detect-replace.c b/src/detect-replace.c index c2587d8e5c..6031c31184 100644 --- a/src/detect-replace.c +++ b/src/detect-replace.c @@ -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) { diff --git a/src/detect-replace.h b/src/detect-replace.h index f7b7c214d2..020f73c45e 100644 --- a/src/detect-replace.h +++ b/src/detect-replace.h @@ -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 @@ -25,8 +25,27 @@ #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 diff --git a/src/detect.c b/src/detect.c index 2fe453c3da..e8950a9707 100644 --- a/src/detect.c +++ b/src/detect.c @@ -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;