From feab99e1de7aeb79ba0349bfe9f02e0a5d108737 Mon Sep 17 00:00:00 2001 From: Pavel Siska Date: Thu, 8 Feb 2024 10:46:41 +0100 Subject: [PATCH] unirecfilter - fix filter syntax error caused by empty filter --- unirecfilter/lib/liburfilter.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/unirecfilter/lib/liburfilter.c b/unirecfilter/lib/liburfilter.c index 9238917b..f3348f41 100644 --- a/unirecfilter/lib/liburfilter.c +++ b/unirecfilter/lib/liburfilter.c @@ -54,13 +54,19 @@ #include "functions.h" #include "liburfilter.h" +#include + urfilter_t *urfilter_create(const char *filter_str, const char *ifc_identifier) { // allocate filter structure urfilter_t *unirec_filter = (urfilter_t *) calloc(1, sizeof (urfilter_t)); if (filter_str) { - unirec_filter->filter = strdup(filter_str); + if (strlen(filter_str) == 0) { + unirec_filter->filter = NULL; + } else { + unirec_filter->filter = strdup(filter_str); + } unirec_filter->ifc_identifier = ifc_identifier; } @@ -87,6 +93,11 @@ int urfilter_compile(urfilter_t *unirec_filter) int urfilter_match(urfilter_t *unirec_filter, const ur_template_t *template, const void *record) { + // empty filter means always TRUE + if (!unirec_filter->filter) { + return URFILTER_TRUE; + } + if (!unirec_filter->tree) { if (unirec_filter->filter) { if (urfilter_compile(unirec_filter) != URFILTER_TRUE) { @@ -98,12 +109,7 @@ int urfilter_match(urfilter_t *unirec_filter, const ur_template_t *template, con return URFILTER_ERROR; } } - - // empty filter means always TRUE - if (!unirec_filter->filter) { - return URFILTER_TRUE; - } - + if (unirec_filter->tree) { return evalAST((struct ast *) unirec_filter->tree, template, record); }