]> mj.ucw.cz Git - checkmail.git/commitdiff
Fix rfc2047 decoding buffer overflow
authorJan Hadrava <had@kam.mff.cuni.cz>
Sat, 9 Sep 2023 23:00:27 +0000 (01:00 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 22 Sep 2023 11:05:01 +0000 (13:05 +0200)
If the rfc2047_decode_word() function fails, only the failed word is
copied into the output.

In the previous version, the rest of the header was copied as well,
which resulted in repetition in the output. This repetition, combined
with the lack of checking the length of the output buffer, could have
led to writing outside the allocated memory.

charset.c

index c80ce9e0dfbbb2b5e9bbb4b958e227b1d40774e6..d32a414eead4eacb54fafccc4822931d1b46f640 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -363,7 +363,12 @@ static void rfc2047_decode (char **pd)
     }
 
     if (rfc2047_decode_word (d, p, dlen) < 0)
-      strcpy(d, p);
+    {
+      n = q - p;
+      if (n > dlen)
+       n = dlen;
+      memcpy (d, p, n);
+    }
     found_encoded = 1;
     s = q;
     n = strlen (d);