From 23211b3a022aaa6a4d3c999d3fc44235f992b4a7 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 20 Jul 2017 17:30:05 -0700 Subject: [PATCH] When guessing an attachment type, don't allow text/plain if there is a null character. (see #2933) Type text/plain should not contain any null characters. Slightly improve the type guesser by forcing an attachment with any null characters to be application/octet-stream. Note the type guesser could use much more improvement, but this is an easy and obvious fix. --- content.h | 1 + sendlib.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/content.h b/content.h index d8a938ffb..b9e2644c8 100644 --- a/content.h +++ b/content.h @@ -34,6 +34,7 @@ struct Content { long hibin; /**< 8-bit characters */ long lobin; /**< unprintable 7-bit chars (eg., control chars) */ + long nulbin; /**< null characters (0x0) */ long crlf; /**< `\r` and `\n` characters */ long ascii; /**< number of ascii chars */ long linemax; /**< length of the longest line in the file */ diff --git a/sendlib.c b/sendlib.c index 72f5ac8cf..fda68c7b6 100644 --- a/sendlib.c +++ b/sendlib.c @@ -595,6 +595,11 @@ static void update_content_info(struct Content *info, struct ContentState *s, info->ascii++; whitespace++; } + else if (ch == 0) + { + info->nulbin++; + info->lobin++; + } else if (ch < 32 || ch == 127) info->lobin++; else @@ -1431,7 +1436,8 @@ struct Body *mutt_make_file_attach(const char *path) if (!att->subtype) { - if (info->lobin == 0 || (info->lobin + info->hibin + info->ascii) / info->lobin >= 10) + if ((info->nulbin == 0) && + (info->lobin == 0 || (info->lobin + info->hibin + info->ascii) / info->lobin >= 10)) { /* * Statistically speaking, there should be more than 10% "lobin" -- 2.40.0