From d397bb25265b8b0926af050c4187cfbc5ab074ca Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 25 Sep 2012 15:19:34 +0200 Subject: fix invalid free caused by optimized script execution --- grammar/rainerscript.c | 3 ++- runtime/modules.c | 3 ++- runtime/modules.h | 1 + runtime/ruleset.c | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index d0c2dc6b..199aaa97 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1035,8 +1035,9 @@ evalVar(struct cnfvar *var, void *usrptr, struct var *ret) #define FREE_TWO_STRINGS \ if(bMustFree) es_deleteStr(estr_r); \ + if(expr->r->nodetype != 'S' && r.datatype == 'S') es_deleteStr(r.d.estr); \ if(bMustFree2) es_deleteStr(estr_l); \ - FREE_BOTH_RET + if(l.datatype == 'S') es_deleteStr(l.d.estr) /* evaluate an expression. * Note that we try to avoid malloc whenever possible (because of diff --git a/runtime/modules.c b/runtime/modules.c index d3c51e90..8675e414 100644 --- a/runtime/modules.c +++ b/runtime/modules.c @@ -313,7 +313,8 @@ finalize_it: /* get the name of a module */ -static uchar *modGetName(modInfo_t *pThis) +uchar * +modGetName(modInfo_t *pThis) { return((pThis->pszName == NULL) ? (uchar*) "" : pThis->pszName); } diff --git a/runtime/modules.h b/runtime/modules.h index 6a143ae3..5041e439 100644 --- a/runtime/modules.h +++ b/runtime/modules.h @@ -191,6 +191,7 @@ PROTOTYPEObj(module); * that are not called from plugins. */ rsRetVal modulesProcessCnf(struct cnfobj *o); +uchar *modGetName(modInfo_t *pThis); rsRetVal addModToCnfList(modInfo_t *pThis); #endif /* #ifndef MODULES_H_INCLUDED */ diff --git a/runtime/ruleset.c b/runtime/ruleset.c index adbce731..2af44bc4 100644 --- a/runtime/ruleset.c +++ b/runtime/ruleset.c @@ -48,6 +48,7 @@ #include "action.h" #include "rainerscript.h" #include "srUtils.h" +#include "modules.h" #include "dirty.h" /* for main ruleset queue creation */ /* static data */ @@ -217,7 +218,7 @@ static rsRetVal execAct(struct cnfstmt *stmt, batch_t *pBatch, sbool *active) { DEFiRet; -dbgprintf("RRRR: execAct: batch of %d elements, active %p\n", batchNumMsgs(pBatch), active); +dbgprintf("RRRR: execAct [%s]: batch of %d elements, active %p\n", modGetName(stmt->d.act->pMod), batchNumMsgs(pBatch), active); pBatch->active = active; stmt->d.act->submitToActQ(stmt->d.act, pBatch); RETiRet; -- cgit v1.2.3