CVE-2020-28016: Heap out-of-bounds write in parse_fix_phrase()
[exim.git] / src / src / parse.c
index cfc1f996f8bc9cefacd07d5a4f172fdc3d2fbac5..fa339520624f51bb091be5a8cb216b556c669f40 100644 (file)
@@ -984,12 +984,12 @@ if (i < len)
 
 /* No non-printers; use the RFC 822 quoting rules */
 
-if (!len)
+if (len <= 0 || len >= INT_MAX/4)
   {
-  return string_copy_taint(US"", is_tainted(phrase));
+  return string_copy_taint(CUS"", is_tainted(phrase));
   }
 
-buffer = store_get(len*4, is_tainted(phrase));
+buffer = store_get((len+1)*4, is_tainted(phrase));
 
 s = phrase;
 end = s + len;
@@ -1134,12 +1134,7 @@ while (s < end)
             {
             if (ss >= end) ss--;
             *t++ = '(';
-            if (ss < s)
-              {
-              /* Someone has ended the string with "<punct>(". */
-              ss = s;
-              }
-            else
+            if (ss > s)
               {
               Ustrncpy(t, s, ss-s);
               t += ss-s;