]> granicus.if.org Git - neomutt/commitdiff
Check for NULL mx_ops in mx.c
authorKevin McCarthy <kevin@8t8.us>
Wed, 21 Sep 2016 20:51:01 +0000 (22:51 +0200)
committerRichard Russon <rich@flatcap.org>
Sun, 2 Oct 2016 14:50:13 +0000 (15:50 +0100)
Eike Rathke reported this happening when in an IMAP index view the
underlying connection was terminated, ctx->mx_ops was NULL and thus
accessing ctx->mx_ops->check segfaulted.

Thanks also to Eike Rathke for the initial patch, for which I expanded
the checks to other functions.

mx.c

diff --git a/mx.c b/mx.c
index 14149250f3acd729aa1a47e783d568f03ed50b8b..78f29c6ce0def8606efc30191fbfd43210b9a2dc 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -1371,7 +1371,7 @@ MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER *hdr, int flags)
   ADDRESS *p = NULL;
   MESSAGE *msg;
 
-  if (!dest->mx_ops->open_new_msg)
+  if (!dest->mx_ops || !dest->mx_ops->open_new_msg)
   {
       dprint (1, (debugfile, "mx_open_new_message(): function unimplemented for mailbox type %d.\n",
               dest->magic));
@@ -1423,7 +1423,7 @@ MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER *hdr, int flags)
 /* check for new mail */
 int mx_check_mailbox (CONTEXT *ctx, int *index_hint)
 {
-  if (!ctx || ctx->magic == 0)
+  if (!ctx || !ctx->mx_ops)
   {
     dprint (1, (debugfile, "mx_check_mailbox: null or invalid context.\n"));
     return -1;
@@ -1437,7 +1437,7 @@ MESSAGE *mx_open_message (CONTEXT *ctx, int msgno)
 {
   MESSAGE *msg;
 
-  if (!ctx->mx_ops->open_msg)
+  if (!ctx->mx_ops || !ctx->mx_ops->open_msg)
   {
     dprint (1, (debugfile, "mx_open_message(): function not implemented for mailbox type %d.\n", ctx->magic));
     return NULL;
@@ -1454,7 +1454,7 @@ MESSAGE *mx_open_message (CONTEXT *ctx, int msgno)
 
 int mx_commit_message (MESSAGE *msg, CONTEXT *ctx)
 {
-  if (!ctx->mx_ops->commit_msg)
+  if (!ctx->mx_ops || !ctx->mx_ops->commit_msg)
     return -1;
 
   if (!(msg->write && ctx->append))
@@ -1472,7 +1472,7 @@ int mx_close_message (CONTEXT *ctx, MESSAGE **msg)
 {
   int r = 0;
 
-  if (ctx->mx_ops->close_msg)
+  if (ctx->mx_ops && ctx->mx_ops->close_msg)
     r = ctx->mx_ops->close_msg (ctx, *msg);
 
   if ((*msg)->path)