changeset 22245:06b45ab1ae72

imap: NOTIFY - Fix crash due to not hooking into commands correctly The pre/post hooks aren't always called immediately when commands are created. They're called only after the command input is being read. Call notify hooks explicitly now immediately when commands are allocated. Fixes a panic with for example: a notify set (selected (Messagenew (uid flags) MessageExpunge FlagChange) personal (MessageNew MessageExpunge FlagChange)) b select inbox c store 1 +flags \deleted d expunge e append inbox {10} Which crashed with: Panic: file imap-notify.c: line 397 (imap_notify_callback): assertion failed: (client->command_queue_size == 0)
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sun, 18 Jun 2017 11:14:05 +0300
parents 9be64b864597
children 0eb4d3b9b0a9
files src/imap/imap-client.c src/imap/imap-notify.c src/imap/imap-notify.h
diffstat 3 files changed, 6 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-client.c	Sun Jun 18 11:19:28 2017 +0300
+++ b/src/imap/imap-client.c	Sun Jun 18 11:14:05 2017 +0300
@@ -833,6 +833,8 @@
 
 	DLLIST_PREPEND(&client->command_queue, cmd);
 	client->command_queue_size++;
+
+	imap_client_notify_command_allocated(client);
 	return cmd;
 }
 
--- a/src/imap/imap-notify.c	Sun Jun 18 11:19:28 2017 +0300
+++ b/src/imap/imap-notify.c	Sun Jun 18 11:14:05 2017 +0300
@@ -16,8 +16,6 @@
 
 #define IMAP_NOTIFY_WATCH_ADD_DELAY_MSECS 1000
 
-static bool notify_hook_registered;
-
 static int imap_notify_list(struct imap_notify_namespace *notify_ns,
 			    const struct mailbox_list_notify_rec *rec,
 			    enum mailbox_info_flags flags)
@@ -451,16 +449,16 @@
 	}
 }
 
-static void imap_notify_cmd_hook_pre(struct client_command_context *cmd)
+void imap_client_notify_command_allocated(struct client *client)
 {
-	struct imap_notify_context *ctx = cmd->client->notify_ctx;
+	struct imap_notify_context *ctx = client->notify_ctx;
 
 	if (ctx == NULL)
 		return;
 
 	/* remove mailbox watcher before starting any commands */
 	if (ctx->watching_mailbox) {
-		mailbox_notify_changes_stop(cmd->client->mailbox);
+		mailbox_notify_changes_stop(client->mailbox);
 		ctx->watching_mailbox = FALSE;
 	}
 	if (ctx->to_watch != NULL)
@@ -474,11 +472,6 @@
 	enum mailbox_list_notify_event notify_events;
 	int ret = -1;
 
-	if (!notify_hook_registered) {
-		notify_hook_registered = TRUE;
-		command_hook_register(imap_notify_cmd_hook_pre, NULL);
-	}
-
 	array_foreach_modifiable(&ctx->namespaces, notify_ns) {
 		notify_events = 0;
 		array_foreach(&notify_ns->mailboxes, notify_boxes) {
--- a/src/imap/imap-notify.h	Sun Jun 18 11:19:28 2017 +0300
+++ b/src/imap/imap-notify.h	Sun Jun 18 11:14:05 2017 +0300
@@ -64,6 +64,7 @@
 int imap_client_notify_newmails(struct client *client);
 void imap_client_notify_finished(struct client *client);
 
+void imap_client_notify_command_allocated(struct client *client);
 void imap_client_notify_command_freed(struct client *client);
 
 int imap_notify_begin(struct imap_notify_context *ctx);