]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix expressions logic for and/or and float values
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Jul 2021 13:41:17 +0000 (14:41 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Jul 2021 13:41:17 +0000 (14:41 +0100)
src/libserver/composites/composites.cxx
src/libutil/expression.c

index 1d3c13a978145c3084c34b4bf80f87decddb8ff5..b03edaf716eb58177361776db3b26d612b2f8f1c 100644 (file)
@@ -747,7 +747,7 @@ rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom) -> doubl
                else {
                        rc = process_single_symbol(cd, sym, &ms, comp_atom);
 
-                       if (rc) {
+                       if (fabs(rc) > epsilon) {
                                process_symbol_removal(atom,
                                                cd,
                                                ms,
@@ -821,6 +821,10 @@ composites_foreach_callback(gpointer key, gpointer value, void *data)
                                return;
                        }
 
+                       msg_debug_composites ("%s: start processing composite %s",
+                                       cd->metric_res->name,
+                                       cd->composite->sym.c_str());
+
                        rc = rspamd_process_expression(comp->expr, RSPAMD_EXPRESSION_FLAG_NOOPT,
                                        cd);
 
index fc967f40442532b09f48ee069bc6eefd9e4ce8ac..553767c3a00e0eef72305d955e02ab90e1ea6540 100644 (file)
@@ -29,7 +29,6 @@
 
 #define MIN_RESORT_EVALS 50
 #define MAX_RESORT_EVALS 150
-#define DOUBLE_EPSILON 1e-9
 
 enum rspamd_expression_elt_type {
        ELT_OP = 0,
@@ -1232,7 +1231,7 @@ rspamd_ast_do_unary_op (struct rspamd_expression_elt *elt, gdouble operand)
 
        switch (elt->p.op.op) {
        case OP_NOT:
-               ret = fabs (operand) > DOUBLE_EPSILON ? 0.0 : 1.0;
+               ret = fabs (operand) > DBL_EPSILON ? 0.0 : 1.0;
                break;
        default:
                g_assert_not_reached ();
@@ -1306,10 +1305,10 @@ rspamd_ast_do_nary_op (struct rspamd_expression_elt *elt, gdouble val, gdouble a
                ret = acc * val;
                break;
        case OP_AND:
-               ret = (acc * val);
+               ret = (acc > DBL_EPSILON) && (val > DBL_EPSILON);
                break;
        case OP_OR:
-               ret = (acc + val);
+               ret = (acc > DBL_EPSILON) || (val > DBL_EPSILON);
                break;
        default:
        case OP_NOT:
@@ -1355,7 +1354,7 @@ rspamd_ast_process_node (struct rspamd_expression *e, GNode *node,
 
                        elt->value = process_data->process_closure (process_data->ud, elt->p.atom);
 
-                       if (fabs (elt->value) > 1e-9) {
+                       if (fabs (elt->value) > DBL_EPSILON) {
                                elt->p.atom->hits ++;
 
                                if (process_data->trace) {