From: Kevin McCarthy Date: Wed, 21 Sep 2016 20:51:01 +0000 (+0200) Subject: Check for NULL mx_ops in mx.c X-Git-Tag: mutt-1-7-1-rel~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=038eacdbad18d04399228c77dc4abbd901542cd9;p=mutt Check for NULL mx_ops in mx.c 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. --- diff --git a/mx.c b/mx.c index fbe82e4c..8f1b397e 100644 --- a/mx.c +++ b/mx.c @@ -1241,7 +1241,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)); @@ -1293,7 +1293,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) + if (!ctx || !ctx->mx_ops) { dprint (1, (debugfile, "mx_check_mailbox: null or invalid context.\n")); return -1; @@ -1307,7 +1307,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; @@ -1324,7 +1324,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)) @@ -1342,7 +1342,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)