diff --git a/src/lib-sieve/plugins/relational/ext-relational-common.c b/src/lib-sieve/plugins/relational/ext-relational-common.c
index 14b4e05818d22b0e12cf74d40d60df9e3bd890f3..a6dd1edfe1ad2e340a7393a8cfa3de382fd9069a 100644
--- a/src/lib-sieve/plugins/relational/ext-relational-common.c
+++ b/src/lib-sieve/plugins/relational/ext-relational-common.c
@@ -43,6 +43,7 @@ bool mcht_relational_validate(struct sieve_validator *valdtr,
 {
 	struct sieve_match_type *mcht;
 	enum relational_match rel_match = REL_MATCH_INVALID;
+	pool_t pool = sieve_ast_argument_pool(ctx->argument);
 	string_t *rel_match_ident;
 
 	/* Check syntax:
@@ -54,14 +55,15 @@ bool mcht_relational_validate(struct sieve_validator *valdtr,
 	 */
 
 	/* Did we get a string in the first place? */
-	if ((*arg)->type != SAAT_STRING) {
+	if (*arg == NULL || (*arg)->type != SAAT_STRING) {
 		sieve_argument_validate_error(
-			valdtr, *arg,
+			valdtr, (*arg == NULL ? ctx->argument : *arg),
 			"the :%s match-type requires a constant string argument being "
 			"one of \"gt\", \"ge\", \"lt\", \"le\", \"eq\" or \"ne\", "
 			"but %s was found",
 			sieve_match_type_name(ctx->match_type),
-			sieve_ast_argument_name(*arg));
+			(*arg == NULL ?
+			 "none" : sieve_ast_argument_name(*arg)));
 		return FALSE;
 	}
 
@@ -138,7 +140,7 @@ bool mcht_relational_validate(struct sieve_validator *valdtr,
 	/* Override the actual match type with a parameter-specific one
 	 * FIXME: ugly!
 	 */
-	mcht = p_new(sieve_ast_argument_pool(*arg), struct sieve_match_type, 1);
+	mcht = p_new(pool, struct sieve_match_type, 1);
 	mcht->object.ext = ctx->match_type->object.ext;
 	SIEVE_OBJECT_SET_DEF(mcht, rel_match_types[
 		REL_MATCH_INDEX(ctx->match_type->object.def->code, rel_match)]);
diff --git a/tests/extensions/relational/errors.svtest b/tests/extensions/relational/errors.svtest
index 927475af1c7125faf213c3ad62136cb7aa4765bc..0973b980104d9f24884a87d185a1b29220672d46 100644
--- a/tests/extensions/relational/errors.svtest
+++ b/tests/extensions/relational/errors.svtest
@@ -4,6 +4,24 @@ require "vnd.dovecot.testsuite";
 require "relational";
 require "comparator-i;ascii-numeric";
 
+/*
+ * Syntax errors
+ */
+
+test "Syntax errors" {
+	if test_script_compile "errors/syntax.sieve" {
+		test_fail "compile should have failed";
+	}
+
+	if test_error :count "ne" "6" {
+		test_fail "wrong number of errors reported";
+	}
+}
+
+/*
+ * Validation errors
+ */
+
 test "Validation errors" {
 	if test_script_compile "errors/validation.sieve" {
 		test_fail "compile should have failed";
diff --git a/tests/extensions/relational/errors/syntax.sieve b/tests/extensions/relational/errors/syntax.sieve
new file mode 100644
index 0000000000000000000000000000000000000000..c9e8188270b3192eb203f85206368576c08164a8
--- /dev/null
+++ b/tests/extensions/relational/errors/syntax.sieve
@@ -0,0 +1,8 @@
+require "relational";
+require "comparator-i;ascii-numeric";
+
+# A semicolon in the middle of things
+if address :count "eq" ;comparator "i;ascii-numeric" "to" "3" { }
+
+# A sub-command in the middle of things
+if not address :comparator "i;ascii-numeric" :value e "to" "3" { }