From 2758f825151925c8fce8cb618cd43fac14ab6d38 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 26 Oct 2016 16:19:13 +0200 Subject: [PATCH] flowvar: cleanups --- src/detect-flowvar.c | 23 +++++++++-------------- src/detect-flowvar.h | 10 ++++------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/detect-flowvar.c b/src/detect-flowvar.c index 962ec6fdc6..e662ad17ab 100644 --- a/src/detect-flowvar.c +++ b/src/detect-flowvar.c @@ -259,11 +259,12 @@ error: * \param sm sigmatch containing the idx to store * \retval 1 or -1 in case of error */ -static int DetectFlowvarPostMatch(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, Packet *p, Signature *s, const SigMatchCtx *ctx) +static int DetectFlowvarPostMatch(ThreadVars *tv, + DetectEngineThreadCtx *det_ctx, + Packet *p, Signature *s, const SigMatchCtx *ctx) { DetectFlowvarList *fs, *prev; const DetectFlowvarData *fd; - const int flow_locked = det_ctx->flow_locked; if (det_ctx->flowvarlist == NULL || p->flow == NULL) return 1; @@ -277,10 +278,7 @@ static int DetectFlowvarPostMatch(ThreadVars *tv, DetectEngineThreadCtx *det_ctx SCLogDebug("adding to the flow %u:", fs->idx); //PrintRawDataFp(stdout, fs->buffer, fs->len); - if (flow_locked) - FlowVarAddStrNoLock(p->flow, fs->idx, fs->buffer, fs->len); - else - FlowVarAddStr(p->flow, fs->idx, fs->buffer, fs->len); + FlowVarAddStrNoLock(p->flow, fs->idx, fs->buffer, fs->len); /* memory at fs->buffer is now the responsibility of * the flowvar code. */ @@ -303,10 +301,10 @@ static int DetectFlowvarPostMatch(ThreadVars *tv, DetectEngineThreadCtx *det_ctx /** \brief Handle flowvar candidate list in det_ctx: * - clean up the list - * - enforce storage for type ALWAYS (luajit) + * - enforce storage for type ALWAYS (vars set from lua) * Only called from DetectFlowvarProcessList() when flowvarlist is not NULL . */ -void DetectFlowvarProcessListInternal(DetectFlowvarList *fs, Flow *f, const int flow_locked) +void DetectFlowvarProcessListInternal(DetectFlowvarList *fs, Flow *f) { DetectFlowvarList *next; @@ -314,18 +312,15 @@ void DetectFlowvarProcessListInternal(DetectFlowvarList *fs, Flow *f, const int next = fs->next; if (fs->type == DETECT_FLOWVAR_TYPE_ALWAYS) { - BUG_ON(f == NULL); SCLogDebug("adding to the flow %u:", fs->idx); //PrintRawDataFp(stdout, fs->buffer, fs->len); - if (flow_locked) - FlowVarAddStrNoLock(f, fs->idx, fs->buffer, fs->len); - else - FlowVarAddStr(f, fs->idx, fs->buffer, fs->len); + FlowVarAddStrNoLock(f, fs->idx, fs->buffer, fs->len); /* memory at fs->buffer is now the responsibility of * the flowvar code. */ - } else + } else { SCFree(fs->buffer); + } SCFree(fs); fs = next; } while (fs != NULL); diff --git a/src/detect-flowvar.h b/src/detect-flowvar.h index 9e72a5bcb5..c8081385b8 100644 --- a/src/detect-flowvar.h +++ b/src/detect-flowvar.h @@ -39,17 +39,15 @@ int DetectFlowvarPostMatchSetup(Signature *s, uint16_t idx); int DetectFlowvarStoreMatch(DetectEngineThreadCtx *, uint16_t, uint8_t *, uint16_t, int); /* For use only by DetectFlowvarProcessList() */ -void DetectFlowvarProcessListInternal(DetectFlowvarList *fs, Flow *f, const int flow_locked); +void DetectFlowvarProcessListInternal(DetectFlowvarList *fs, Flow *f); static inline void DetectFlowvarProcessList(DetectEngineThreadCtx *det_ctx, Flow *f) { DetectFlowvarList *fs = det_ctx->flowvarlist; - const int flow_locked = det_ctx->flow_locked; - SCLogDebug("det_ctx->flowvarlist %p", fs); - - if (fs != NULL) { + SCLogDebug("flow %p det_ctx->flowvarlist %p", f, fs); + if (f && fs != NULL) { det_ctx->flowvarlist = NULL; - DetectFlowvarProcessListInternal(fs, f, flow_locked); + DetectFlowvarProcessListInternal(fs, f); } }