From 9420e6dee96fc70b81792f547891083d0c87a0f8 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Tue, 30 Dec 2014 23:01:04 +0100
Subject: [PATCH] lib-sieve: Fixed crash in validation of the string parameter
 of the comparator tag. It couldn't handle a missing parameter (which also
 means missing arguments of the test itself in most cases). This is fixed by
 using the sieve_validate_tag_parameter() utility function. Testsuite is also
 extended.

---
 src/lib-sieve/sieve-comparators.c     |  9 ++-------
 tests/compile/errors.svtest           | 14 ++++++++++++++
 tests/compile/errors/comparator.sieve | 21 +++++++++++++++++++++
 3 files changed, 37 insertions(+), 7 deletions(-)
 create mode 100644 tests/compile/errors/comparator.sieve

diff --git a/src/lib-sieve/sieve-comparators.c b/src/lib-sieve/sieve-comparators.c
index a66b28e2e..c682031ac 100644
--- a/src/lib-sieve/sieve-comparators.c
+++ b/src/lib-sieve/sieve-comparators.c
@@ -140,16 +140,11 @@ static bool tag_comparator_validate
 	/* Check syntax:
 	 *   ":comparator" <comparator-name: string>
 	 */
-	if ( (*arg)->type != SAAT_STRING ) {
-		sieve_argument_validate_error(valdtr, *arg,
-			":comparator tag requires one string argument, but %s was found",
-			sieve_ast_argument_name(*arg) );
+	if ( !sieve_validate_tag_parameter
+		(valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, FALSE) ) {
 		return FALSE;
 	}
 
-	if ( !sieve_validator_argument_activate(valdtr, cmd, *arg, FALSE) )
-		return FALSE;
-
 	/* FIXME: We can currently only handle string literal argument, so
 	 * variables are not allowed.
 	 */
diff --git a/tests/compile/errors.svtest b/tests/compile/errors.svtest
index b2c94ab95..c2bc29251 100644
--- a/tests/compile/errors.svtest
+++ b/tests/compile/errors.svtest
@@ -242,6 +242,20 @@ test "Keep errors (FIXME: count only)" {
 	}
 }
 
+/*
+ * COMPARATOR errors
+ */
+
+test "COMPARATOR errors (FIXME: count only)" {
+	if test_script_compile "errors/comparator.sieve" {
+		test_fail "compile should have failed.";
+	}
+
+	if not test_error :count "eq" :comparator "i;ascii-numeric" "6" {
+		test_fail "wrong number of errors reported";
+	}
+}
+
 /*
  * ADDRESS-PART errors
  */
diff --git a/tests/compile/errors/comparator.sieve b/tests/compile/errors/comparator.sieve
new file mode 100644
index 000000000..368b56bfc
--- /dev/null
+++ b/tests/compile/errors/comparator.sieve
@@ -0,0 +1,21 @@
+/*
+ * Address part errors
+ *
+ * Total errors: 5 (+1 = 6)
+ */
+
+# 1: No argument
+if address :comparator { }
+
+# 2: Number argument
+if address :comparator 1 "from" "frop" { }
+
+# 3: String list argument
+if address :comparator ["a", "b"] "from" "frop" { }
+
+# 4: Unknown tag
+if address :comparator :frop "from" "frop" { }
+
+# 5: Known tag
+if address :comparator :all "from" "frop" { }
+
-- 
GitLab