From: Kevin McCarthy Date: Fri, 21 Jul 2017 00:30:05 +0000 (-0700) Subject: When guessing an attachment type, don't allow text/plain if there is a null character... X-Git-Tag: mutt-1-9-rel~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2aa03f79892aa193f3e8bbb2037fe666a8122071;p=mutt 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. --- diff --git a/mutt.h b/mutt.h index 50684fc7..465f7055 100644 --- a/mutt.h +++ b/mutt.h @@ -651,6 +651,7 @@ typedef 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 c79800db..75d270b2 100644 --- a/sendlib.c +++ b/sendlib.c @@ -572,6 +572,11 @@ static void update_content_info (CONTENT *info, CONTENT_STATE *s, char *d, size_ info->ascii++; whitespace++; } + else if (ch == 0) + { + info->nulbin++; + info->lobin++; + } else if (ch < 32 || ch == 127) info->lobin++; else @@ -1362,23 +1367,8 @@ BODY *mutt_make_file_attach (const char *path) /* Attempt to determine the appropriate content-type based on the filename * suffix. */ - -#if 0 - - if ((n = mutt_lookup_mime_type (buf, sizeof (buf), xbuf, sizeof (xbuf), path)) != TYPEOTHER - || *xbuf != '\0') - { - att->type = n; - att->subtype = safe_strdup (buf); - att->xtype = safe_strdup (xbuf); - } - -#else - mutt_lookup_mime_type (att, path); -#endif - if ((info = mutt_get_content_info (path, att)) == NULL) { mutt_free_body (&att); @@ -1387,7 +1377,8 @@ 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"