From 96dc4134dc7e4b25e2e5f922323e815a8fb5fc35 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Wed, 21 Sep 2016 22:51:01 +0200 Subject: [PATCH] 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. --- mx.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mx.c b/mx.c index 14149250f..78f29c6ce 100644 --- 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) -- 2.40.0