diff --git a/src/lib-sieve/sieve-error.c b/src/lib-sieve/sieve-error.c
index c2699bd65ea65d23c89e740e955f2d9c6c9562b6..72d0ea5d4e704ae3a708ae4ad62c731a210cb3f1 100644
--- a/src/lib-sieve/sieve-error.c
+++ b/src/lib-sieve/sieve-error.c
@@ -100,7 +100,7 @@ void sieve_direct_logv(struct sieve_instance *svinst,
 {
 	if ((flags & SIEVE_ERROR_FLAG_GLOBAL) != 0 &&
 	    (ehandler == NULL || ehandler->parent == NULL) &&
-	    (!ehandler->master_log ||
+	    (ehandler == NULL || !ehandler->master_log ||
 	     (params->log_type > LOG_TYPE_INFO &&
 	      (flags & SIEVE_ERROR_FLAG_GLOBAL_MAX_INFO) != 0))) {
 		struct sieve_error_params new_params = *params;
@@ -117,7 +117,7 @@ void sieve_direct_logv(struct sieve_instance *svinst,
 
 		va_end(args_copy);
 
-		if (ehandler->master_log)
+		if (ehandler != NULL && ehandler->master_log)
 			return;
 	}