diff --git a/src/lib-sieve/sieve-plugins.c b/src/lib-sieve/sieve-plugins.c
index a93f9de05326a831bac51d6a090223727b68daa0..b81ac910c2473453716f646b5a3ae785b0a9ddcb 100644
--- a/src/lib-sieve/sieve-plugins.c
+++ b/src/lib-sieve/sieve-plugins.c
@@ -142,7 +142,7 @@ void sieve_plugins_load(struct sieve_instance *svinst, const char *path, const c
 			struct sieve_plugin *plugin_last;
 
 			plugin_last = svinst->plugins;
-			while ( plugin_last != NULL )
+			while ( plugin_last->next != NULL )
 				plugin_last = plugin_last->next;
 
 			plugin_last->next = plugin;