824f1e
From e5ed080c00e59701ca62ef9b2a6d2612ebf765a5 Mon Sep 17 00:00:00 2001
824f1e
From: Kevin McCarthy <kevin@8t8.us>
824f1e
Date: Tue, 5 Apr 2022 11:05:52 -0700
824f1e
Subject: [PATCH] Fix uudecode buffer overflow.
824f1e
824f1e
mutt_decode_uuencoded() used each line's initial "length character"
824f1e
without any validation.  It would happily read past the end of the
824f1e
input line, and with a suitable value even past the length of the
824f1e
input buffer.
824f1e
824f1e
As I noted in ticket 404, there are several other changes that could
824f1e
be added to make the parser more robust.  However, to avoid
824f1e
accidentally introducing another bug or regression, I'm restricting
824f1e
this patch to simply addressing the overflow.
824f1e
824f1e
Thanks to Tavis Ormandy for reporting the issue, along with a sample
824f1e
message demonstrating the problem.
824f1e
---
824f1e
 handler.c | 4 ++--
824f1e
 1 file changed, 2 insertions(+), 2 deletions(-)
824f1e
824f1e
diff --git a/handler.c b/handler.c
824f1e
index d1b4bc73..c97cf0cb 100644
824f1e
--- a/handler.c
824f1e
+++ b/handler.c
824f1e
@@ -404,9 +404,9 @@ static void mutt_decode_uuencoded (STATE *s, LOFF_T len, int istext, iconv_t cd)
824f1e
     pt = tmps;
824f1e
     linelen = decode_byte (*pt);
824f1e
     pt++;
824f1e
-    for (c = 0; c < linelen;)
824f1e
+    for (c = 0; c < linelen && *pt;)
824f1e
     {
824f1e
-      for (l = 2; l <= 6; l += 2)
824f1e
+      for (l = 2; l <= 6 && *pt && *(pt + 1); l += 2)
824f1e
       {
824f1e
 	out = decode_byte (*pt) << l;
824f1e
 	pt++;
824f1e
-- 
824f1e
2.34.1
824f1e