changeset: 6573:2a152212cd9a user: Vincent Lefevre <vinc...@vinc17.org> date: Tue Mar 15 18:01:44 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/2a152212cd9a
Check return value of ftruncate() in mbox_sync_mailbox(). Generate an error in the event that ftruncate() fails. changeset: 6574:29b254ac7c12 user: Kevin McCarthy <ke...@8t8.us> date: Tue Mar 15 18:04:26 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/29b254ac7c12 Prevent ctx->fp from being closed twice in the event of an error. The previous patch from Vincent exposed a crash if ftruncate() fails in mbox_sync_mailbox(). Change fclose() to safe_fclose(), to avoid it being called twice. diffs (25 lines): diff -r 73c8c033e184 -r 29b254ac7c12 mbox.c --- a/mbox.c Sun Mar 13 19:04:12 2016 -0700 +++ b/mbox.c Tue Mar 15 18:04:26 2016 -0700 @@ -968,7 +968,11 @@ if (i == 0) { ctx->size = ftello (ctx->fp); /* update the size of the mailbox */ - ftruncate (fileno (ctx->fp), ctx->size); + if (ftruncate (fileno (ctx->fp), ctx->size) != 0) + { + i = -1; + dprint (1, (debugfile, "mbox_sync_mailbox: ftruncate() failed\n")); + } } } @@ -976,7 +980,7 @@ fp = NULL; mbox_unlock_mailbox (ctx); - if (fclose (ctx->fp) != 0 || i == -1) + if (safe_fclose (&ctx->fp) != 0 || i == -1) { /* error occurred while writing the mailbox back, so keep the temp copy * around