File syslog-ng-3.3.1-filters.diff of Package syslog-ng
commit 4b438115f6387eb52b6c39c1f751ecf0c4a5ac5f
Author: Balazs Scheidler <bazsi@balabit.hu>
Date: Sun Oct 23 20:19:58 2011 +0200
filters: fixed filter() evaluation when embedded as an AND/OR subexpression
When introducing the "init" method for filters one case was omitted: even
though AND and OR expressions don't want to do anything on init, their
subexpressions might, so this patch adds an init function to AND and OR
which does nothing but calls the same for its "left" and "right"
subexpression.
This patch fixes filter("xxx") expression evaluation when that is
not a single expression, but rather included in an AND or OR.
Reported-By: Leonid Isaev <lisaev@umail.iu.edu>
Cc: <syslog-ng-stable@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
diff --git a/lib/filter.c b/lib/filter.c
index a551559..d88e439 100644
--- a/lib/filter.c
+++ b/lib/filter.c
@@ -84,6 +84,17 @@ typedef struct _FilterOp
} FilterOp;
static void
+fop_init(FilterExprNode *s, GlobalConfig *cfg)
+{
+ FilterOp *self = (FilterOp *) s;
+
+ if (self->left && self->left->init)
+ self->left->init(self->left, cfg);
+ if (self->right && self->right->init)
+ self->right->init(self->right, cfg);
+}
+
+static void
fop_free(FilterExprNode *s)
{
FilterOp *self = (FilterOp *) s;
@@ -92,6 +103,14 @@ fop_free(FilterExprNode *s)
filter_expr_unref(self->right);
}
+static void
+fop_init_instance(FilterOp *self)
+{
+ filter_expr_node_init(&self->super);
+ self->super.init = fop_init;
+ self->super.free_fn = fop_free;
+}
+
static gboolean
fop_or_eval(FilterExprNode *s, LogMessage *msg)
{
@@ -105,9 +124,8 @@ fop_or_new(FilterExprNode *e1, FilterExprNode *e2)
{
FilterOp *self = g_new0(FilterOp, 1);
- filter_expr_node_init(&self->super);
+ fop_init_instance(self);
self->super.eval = fop_or_eval;
- self->super.free_fn = fop_free;
self->super.modify = e1->modify || e2->modify;
self->left = e1;
self->right = e2;
@@ -128,9 +146,8 @@ fop_and_new(FilterExprNode *e1, FilterExprNode *e2)
{
FilterOp *self = g_new0(FilterOp, 1);
- filter_expr_node_init(&self->super);
+ fop_init_instance(self);
self->super.eval = fop_and_eval;
- self->super.free_fn = fop_free;
self->super.modify = e1->modify || e2->modify;
self->left = e1;
self->right = e2;