From 2ec7cd16e512271dbb30be66c3af1479be66818c Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Thu, 9 Nov 2017 08:50:52 +0000 Subject: [PATCH] Sanitize mutt_copy_message* APIs --- attach.c | 2 +- commands.c | 4 ++-- copy.c | 21 +++++++++++---------- copy.h | 6 ++---- mbox.c | 2 +- mh.c | 2 +- ncrypt/crypt.c | 20 ++++++++++---------- ncrypt/smime.c | 6 +++--- recvcmd.c | 8 ++++---- send.c | 4 ++-- sendlib.c | 2 +- 11 files changed, 38 insertions(+), 39 deletions(-) diff --git a/attach.c b/attach.c index c4736a083..a5ac6762e 100644 --- a/attach.c +++ b/attach.c @@ -795,7 +795,7 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct if (ctx.magic == MUTT_MBOX || ctx.magic == MUTT_MMDF) chflags = CH_FROM | CH_UPDATE_LEN; chflags |= (ctx.magic == MUTT_MAILDIR ? CH_NOSTATUS : CH_UPDATE); - if (mutt_copy_message(msg->fp, fp, hn, hn->content, 0, chflags) == 0 && + if (mutt_copy_message_fp(msg->fp, fp, hn, 0, chflags) == 0 && mx_commit_message(msg, &ctx) == 0) r = 0; else diff --git a/commands.c b/commands.c index 652912ca6..fa1343b3c 100644 --- a/commands.c +++ b/commands.c @@ -167,7 +167,7 @@ int mutt_display_message(struct Header *cur) if (Context->magic == MUTT_NOTMUCH) chflags |= CH_VIRTUAL; #endif - res = mutt_open_copy_message(fpout, Context, cur, cmflags, chflags); + res = mutt_copy_message_ctx(fpout, Context, cur, cmflags, chflags); if ((safe_fclose(&fpout) != 0 && errno != EPIPE) || res < 0) { @@ -384,7 +384,7 @@ static void pipe_msg(struct Header *h, FILE *fp, int decode, int print) if (decode) mutt_parse_mime_message(Context, h); - mutt_open_copy_message(fp, Context, h, cmflags, chflags); + mutt_copy_message_ctx(fp, Context, h, cmflags, chflags); } /** diff --git a/copy.c b/copy.c index ee73f2151..f4bd48b59 100644 --- a/copy.c +++ b/copy.c @@ -523,7 +523,7 @@ static int count_delete_lines(FILE *fp, struct Body *b, LOFF_T *length, size_t d } /** - * mutt_copy_message - make a copy of a message + * mutt_copy_message_fp - make a copy of a message from a FILE pointer * @param fpout Where to write output * @param fpin Where to get input * @param hdr Header of message being copied @@ -540,9 +540,10 @@ static int count_delete_lines(FILE *fp, struct Body *b, LOFF_T *length, size_t d * * #MUTT_CM_DECODE_PGP used for decoding PGP messages * * #MUTT_CM_CHARCONV perform character set conversion */ -int mutt_copy_message(FILE *fpout, FILE *fpin, struct Header *hdr, - struct Body *body, int flags, int chflags) +int mutt_copy_message_fp(FILE *fpout, FILE *fpin, struct Header *hdr, int flags, + int chflags) { + struct Body *body = hdr->content; char prefix[SHORT_STRING]; struct State s; LOFF_T new_offset = -1; @@ -743,13 +744,13 @@ int mutt_copy_message(FILE *fpout, FILE *fpin, struct Header *hdr, } /** - * mutt_open_copy_message - Copy a message + * mutt_copy_message_ctx - Copy a message from a Context * * should be made to return -1 on fatal errors, and 1 on non-fatal errors * like partial decode, where it is worth displaying as much as possible */ -int mutt_open_copy_message(FILE *fpout, struct Context *src, struct Header *hdr, - int flags, int chflags) +int mutt_copy_message_ctx(FILE *fpout, struct Context *src, struct Header *hdr, + int flags, int chflags) { struct Message *msg = NULL; int r; @@ -757,7 +758,7 @@ int mutt_open_copy_message(FILE *fpout, struct Context *src, struct Header *hdr, msg = mx_open_message(src, hdr->msgno); if (!msg) return -1; - if ((r = mutt_copy_message(fpout, msg->fp, hdr, hdr->content, flags, chflags)) == 0 && + if ((r = mutt_copy_message_fp(fpout, msg->fp, hdr, flags, chflags)) == 0 && (ferror(fpout) || feof(fpout))) { mutt_debug(1, "mutt_copy_message failed to detect EOF!\n"); @@ -780,7 +781,7 @@ int mutt_open_copy_message(FILE *fpout, struct Context *src, struct Header *hdr, * @retval -1 on error */ static int append_message(struct Context *dest, FILE *fpin, struct Context *src, - struct Header *hdr, struct Body *body, int flags, int chflags) + struct Header *hdr, int flags, int chflags) { char buf[STRING]; struct Message *msg = NULL; @@ -797,7 +798,7 @@ static int append_message(struct Context *dest, FILE *fpin, struct Context *src, if (dest->magic == MUTT_MBOX || dest->magic == MUTT_MMDF) chflags |= CH_FROM | CH_FORCE_FROM; chflags |= (dest->magic == MUTT_MAILDIR ? CH_NOSTATUS : CH_UPDATE); - r = mutt_copy_message(msg->fp, fpin, hdr, body, flags, chflags); + r = mutt_copy_message_fp(msg->fp, fpin, hdr, flags, chflags); if (mx_commit_message(msg, dest) != 0) r = -1; @@ -819,7 +820,7 @@ int mutt_append_message(struct Context *dest, struct Context *src, msg = mx_open_message(src, hdr->msgno); if (!msg) return -1; - r = append_message(dest, msg->fp, src, hdr, hdr->content, cmflags, chflags); + r = append_message(dest, msg->fp, src, hdr, cmflags, chflags); mx_close_message(src, &msg); return r; } diff --git a/copy.h b/copy.h index 0eecc34d9..98ed22c20 100644 --- a/copy.h +++ b/copy.h @@ -72,10 +72,8 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int mutt_copy_header(FILE *in, struct Header *h, FILE *out, int flags, const char *prefix); -int mutt_copy_message(FILE *fpout, FILE *fpin, struct Header *hdr, struct Body *body, - int flags, int chflags); - -int mutt_open_copy_message(FILE *fpout, struct Context *src, struct Header *hdr, int flags, int chflags); +int mutt_copy_message_fp (FILE *fpout, FILE *fpin, struct Header *hdr, int flags, int chflags); +int mutt_copy_message_ctx(FILE *fpout, struct Context *src, struct Header *hdr, int flags, int chflags); int mutt_append_message(struct Context *dest, struct Context *src, struct Header *hdr, int cmflags, int chflags); diff --git a/mbox.c b/mbox.c index 8093c5185..858a33225 100644 --- a/mbox.c +++ b/mbox.c @@ -1167,7 +1167,7 @@ static int mbox_sync_mailbox(struct Context *ctx, int *index_hint) */ newOffset[i - first].hdr = ftello(fp) + offset; - if (mutt_open_copy_message(fp, ctx, ctx->hdrs[i], MUTT_CM_UPDATE, + if (mutt_copy_message_ctx(fp, ctx, ctx->hdrs[i], MUTT_CM_UPDATE, CH_FROM | CH_UPDATE | CH_UPDATE_LEN) != 0) { mutt_perror(tempfile); diff --git a/mh.c b/mh.c index 845f91bfe..3a3b82de7 100644 --- a/mh.c +++ b/mh.c @@ -1767,7 +1767,7 @@ static int mh_rewrite_message(struct Context *ctx, int msgno) if (!dest) return -1; - rc = mutt_open_copy_message(dest->fp, ctx, h, MUTT_CM_UPDATE, CH_UPDATE | CH_UPDATE_LEN); + rc = mutt_copy_message_ctx(dest->fp, ctx, h, MUTT_CM_UPDATE, CH_UPDATE | CH_UPDATE_LEN); if (rc == 0) { snprintf(oldpath, _POSIX_PATH_MAX, "%s/%s", ctx->path, h->path); diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index f7c482738..fd4a8042b 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -724,7 +724,7 @@ void crypt_extract_keys_from_messages(struct Header *h) if ((WithCrypto & APPLICATION_PGP) && (hi->security & APPLICATION_PGP)) { - mutt_open_copy_message(fpout, Context, hi, MUTT_CM_DECODE | MUTT_CM_CHARCONV, 0); + mutt_copy_message_ctx(fpout, Context, hi, MUTT_CM_DECODE | MUTT_CM_CHARCONV, 0); fflush(fpout); mutt_endwin(_("Trying to extract PGP keys...\n")); @@ -734,11 +734,11 @@ void crypt_extract_keys_from_messages(struct Header *h) if ((WithCrypto & APPLICATION_SMIME) && (hi->security & APPLICATION_SMIME)) { if (hi->security & ENCRYPT) - mutt_open_copy_message(fpout, Context, hi, - MUTT_CM_NOHEADER | MUTT_CM_DECODE_CRYPT | MUTT_CM_DECODE_SMIME, - 0); + mutt_copy_message_ctx(fpout, Context, hi, + MUTT_CM_NOHEADER | MUTT_CM_DECODE_CRYPT | MUTT_CM_DECODE_SMIME, + 0); else - mutt_open_copy_message(fpout, Context, hi, 0, 0); + mutt_copy_message_ctx(fpout, Context, hi, 0, 0); fflush(fpout); if (hi->env->from) @@ -764,7 +764,7 @@ void crypt_extract_keys_from_messages(struct Header *h) { if ((WithCrypto & APPLICATION_PGP) && (h->security & APPLICATION_PGP)) { - mutt_open_copy_message(fpout, Context, h, MUTT_CM_DECODE | MUTT_CM_CHARCONV, 0); + mutt_copy_message_ctx(fpout, Context, h, MUTT_CM_DECODE | MUTT_CM_CHARCONV, 0); fflush(fpout); mutt_endwin(_("Trying to extract PGP keys...\n")); crypt_pgp_invoke_import(tempfname); @@ -773,11 +773,11 @@ void crypt_extract_keys_from_messages(struct Header *h) if ((WithCrypto & APPLICATION_SMIME) && (h->security & APPLICATION_SMIME)) { if (h->security & ENCRYPT) - mutt_open_copy_message(fpout, Context, h, - MUTT_CM_NOHEADER | MUTT_CM_DECODE_CRYPT | MUTT_CM_DECODE_SMIME, - 0); + mutt_copy_message_ctx(fpout, Context, h, + MUTT_CM_NOHEADER | MUTT_CM_DECODE_CRYPT | MUTT_CM_DECODE_SMIME, + 0); else - mutt_open_copy_message(fpout, Context, h, 0, 0); + mutt_copy_message_ctx(fpout, Context, h, 0, 0); fflush(fpout); if (h->env->from) diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 0ce8a1192..41f0d912d 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -1250,10 +1250,10 @@ int smime_verify_sender(struct Header *h) } if (h->security & ENCRYPT) - mutt_open_copy_message(fpout, Context, h, MUTT_CM_DECODE_CRYPT & MUTT_CM_DECODE_SMIME, - CH_MIME | CH_WEED | CH_NONEWLINE); + mutt_copy_message_ctx(fpout, Context, h, MUTT_CM_DECODE_CRYPT & MUTT_CM_DECODE_SMIME, + CH_MIME | CH_WEED | CH_NONEWLINE); else - mutt_open_copy_message(fpout, Context, h, 0, 0); + mutt_copy_message_ctx(fpout, Context, h, 0, 0); fflush(fpout); safe_fclose(&fpout); diff --git a/recvcmd.c b/recvcmd.c index 229a26191..c3587d48a 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -617,7 +617,7 @@ static void attach_forward_msgs(FILE *fp, struct Header *hdr, if (cur) { mutt_forward_intro(Context, cur->hdr, tmpfp); - mutt_copy_message(tmpfp, fp, cur->hdr, cur->hdr->content, cmflags, chflags); + mutt_copy_message_fp(tmpfp, fp, cur->hdr, cmflags, chflags); mutt_forward_trailer(Context, cur->hdr, tmpfp); } else @@ -627,8 +627,8 @@ static void attach_forward_msgs(FILE *fp, struct Header *hdr, if (actx->idx[i]->content->tagged) { mutt_forward_intro(Context, actx->idx[i]->content->hdr, tmpfp); - mutt_copy_message(tmpfp, actx->idx[i]->fp, actx->idx[i]->content->hdr, - actx->idx[i]->content->hdr->content, cmflags, chflags); + mutt_copy_message_fp(tmpfp, actx->idx[i]->fp, + actx->idx[i]->content->hdr, cmflags, chflags); mutt_forward_trailer(Context, actx->idx[i]->content->hdr, tmpfp); } } @@ -785,7 +785,7 @@ static void attach_include_reply(FILE *fp, FILE *tmpfp, struct Header *cur, int cmflags |= MUTT_CM_WEED; } - mutt_copy_message(tmpfp, fp, cur, cur->content, cmflags, chflags); + mutt_copy_message_fp(tmpfp, fp, cur, cmflags, chflags); mutt_make_post_indent(Context, cur, tmpfp); } diff --git a/send.c b/send.c index b346cc8c9..319c96590 100644 --- a/send.c +++ b/send.c @@ -468,7 +468,7 @@ static int include_forward(struct Context *ctx, struct Header *cur, FILE *out) * rather than send action */ chflags |= CH_DISPLAY; - mutt_open_copy_message(out, ctx, cur, cmflags, chflags); + mutt_copy_message_ctx(out, ctx, cur, cmflags, chflags); mutt_forward_trailer(ctx, cur, out); return 0; } @@ -522,7 +522,7 @@ static int include_reply(struct Context *ctx, struct Header *cur, FILE *out) cmflags |= MUTT_CM_WEED; } - mutt_open_copy_message(out, ctx, cur, cmflags, chflags); + mutt_copy_message_ctx(out, ctx, cur, cmflags, chflags); mutt_make_post_indent(ctx, cur, out); diff --git a/sendlib.c b/sendlib.c index e417cf7a0..2d895e215 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1415,7 +1415,7 @@ struct Body *mutt_make_message_attach(struct Context *ctx, struct Header *hdr, i } } - mutt_open_copy_message(fp, ctx, hdr, cmflags, chflags); + mutt_copy_message_ctx(fp, ctx, hdr, cmflags, chflags); fflush(fp); rewind(fp); -- 2.40.0