]> granicus.if.org Git - neomutt/commitdiff
When guessing an attachment type, don't allow text/plain if there is a null character...
authorKevin McCarthy <kevin@8t8.us>
Fri, 21 Jul 2017 00:30:05 +0000 (17:30 -0700)
committerRichard Russon <rich@flatcap.org>
Thu, 3 Aug 2017 15:52:53 +0000 (16:52 +0100)
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
sendlib.c

index d8a938ffb90db113de04b9395422c29822775873..b9e2644c863aab343812684ff12a5edb636bd149 100644 (file)
--- 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 */
index 72f5ac8cfed178e057cadb2954271d81187e64aa..fda68c7b689add9699e789908272a222e1875521 100644 (file)
--- 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"