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.
pull/1171/head
Ken Steele 12 years ago committed by Victor Julien
parent 9a36f7f633
commit 60c46170b0

@ -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) {

@ -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

@ -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;

Loading…
Cancel
Save