[packages/neomutt] Rel 3. Backport memory-safety fixes from upstream main.

arekm arekm at pld-linux.org
Thu Oct 29 08:50:30 CET 2026


commit 0a58e0d8f81914bef2ff0913f1bc364609547eca
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Oct 29 03:43:06 2026 +0100

    Rel 3. Backport memory-safety fixes from upstream main.

 base64-leading-pad.patch       |  26 +++++++++
 date-tm_mon-bound.patch        |  23 ++++++++
 expando-justify-overrun.patch  |  75 ++++++++++++++++++++++++
 imap-cram-challenge-oob.patch  |  30 ++++++++++
 imap-cram-md5-key.patch        |  32 +++++++++++
 imap-status-literal.patch      |  39 +++++++++++++
 imap-utf7-oob.patch            |  33 +++++++++++
 neomutt.spec                   |  32 +++++++++--
 nntp-overview-fmt-oob.patch    |  47 +++++++++++++++
 parse-references-oob.patch     | 126 +++++++++++++++++++++++++++++++++++++++++
 thread-dangling-pointers.patch |  60 ++++++++++++++++++++
 11 files changed, 519 insertions(+), 4 deletions(-)
---
diff --git a/neomutt.spec b/neomutt.spec
index b1c1d9a..2c7fadb 100644
--- a/neomutt.spec
+++ b/neomutt.spec
@@ -22,16 +22,25 @@ Summary(tr.UTF-8):	NeoMutt elektronik posta programı
 Summary(uk.UTF-8):	Поштова клієнтська програма NeoMutt
 Name:		neomutt
 Version:	20260616
-Release:	2
+Release:	3
 License:	GPL v2+
 Group:		Applications/Mail
 Source0:	https://github.com/neomutt/neomutt/archive/%{version}.tar.gz
 # Source0-md5:	62598030ad28173f18e8c04ead0c5e68
 Patch0:		flags.patch
+# fixes from upstream main/release branches after 20260616, https://github.com/neomutt/neomutt
+Patch1:		thread-dangling-pointers.patch
+Patch2:		imap-cram-challenge-oob.patch
+Patch3:		imap-cram-md5-key.patch
+Patch4:		imap-status-literal.patch
+Patch5:		imap-utf7-oob.patch
+Patch6:		nntp-overview-fmt-oob.patch
+Patch7:		parse-references-oob.patch
+Patch8:		base64-leading-pad.patch
+Patch9:		date-tm_mon-bound.patch
+Patch10:	expando-justify-overrun.patch
 Source1:	%{name}.desktop
-URL:		http://www.mutt.org/
-BuildRequires:	autoconf >= 2.54
-BuildRequires:	automake >= 1.6
+URL:		https://neomutt.org/
 %{?with_sasl:BuildRequires:	cyrus-sasl-devel >= 2.1.0}
 %{?with_bdb:BuildRequires:	db-devel >= 4.0}
 BuildRequires:	docbook-dtd42-xml
@@ -49,6 +58,7 @@ BuildRequires:	lz4-devel
 BuildRequires:	ncurses-devel >= 5.0
 BuildRequires:	openssl-devel >= 0.9.7d
 %{?with_pcre2:BuildRequires:	pcre2-8-devel}
+BuildRequires:	pkgconfig
 %{?with_qdbm:BuildRequires:	qdbm-devel}
 BuildRequires:	rpm-build >= 4.6
 BuildRequires:	tcl
@@ -149,6 +159,16 @@ Utility to add S/MIME certificate to the database used by neomutt.
 %prep
 %setup -q
 %patch -P0 -p1
+%patch -P1 -p1
+%patch -P2 -p1
+%patch -P3 -p1
+%patch -P4 -p1
+%patch -P5 -p1
+%patch -P6 -p1
+%patch -P7 -p1
+%patch -P8 -p1
+%patch -P9 -p1
+%patch -P10 -p1
 
 %{__sed} -i -e '1 s,#!.*env python3,#!%{__python3},' contrib/oauth2/mutt_oauth2.py
 
@@ -206,6 +226,8 @@ EOF
 
 %{__rm} -r $RPM_BUILD_ROOT%{_datadir}/neomutt/account-command/macos-keychain
 %{__rm} -r $RPM_BUILD_ROOT%{_datadir}/neomutt/logo
+# shipped as %doc of the subpackages
+%{__rm} $RPM_BUILD_ROOT%{_datadir}/neomutt/{account-command/gpg-json,oauth2}/README.md
 
 # keep manual.txt.gz, the rest is installed as %doc
 %{__rm} -r $RPM_BUILD_ROOT%{_docdir}/%{name}/[!m]*
@@ -229,10 +251,12 @@ rm -rf $RPM_BUILD_ROOT
 
 %dir %{_datadir}/neomutt
 %dir %{_datadir}/neomutt/account-command
+%{_datadir}/neomutt/account-command/README.md
 %dir %{_datadir}/neomutt/colorschemes
 %{_datadir}/neomutt/colorschemes/*.neomuttrc
 %{_datadir}/neomutt/mime.types
 %dir %{_datadir}/neomutt/vim-keys
+%{_datadir}/neomutt/vim-keys/README.md
 %{_datadir}/neomutt/vim-keys/vim-keys.rc
 %{_docdir}/%{name}
 %{_desktopdir}/neomutt.desktop
diff --git a/base64-leading-pad.patch b/base64-leading-pad.patch
new file mode 100644
index 0000000..ede2f03
--- /dev/null
+++ b/base64-leading-pad.patch
@@ -0,0 +1,26 @@
+From c8a2e5a7d07234a630f63617da3951dd707a5259 Mon Sep 17 00:00:00 2001
+From: Yvonne <yvonnelxxxx at gmail.com>
+Date: Mon, 10 Aug 2026 12:30:07 +0800
+Subject: [PATCH 08/10] fix decode_base64 issue when leading is =
+
+(cherry picked from commit eb4f57801f4d275e349ba3b5fc6a27d6cc95deec)
+---
+ handler.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/handler.c b/handler.c
+index 5e1e6eb..7d27355 100644
+--- a/handler.c
++++ b/handler.c
+@@ -1562,7 +1562,11 @@ void mutt_decode_base64(struct State *state, size_t len, bool istext, iconv_t cd
+     }
+ 
+     const int c1 = base64val(buf[0]);
++    if (c1 == -1) /* '=' (or any non-base64 char) at slot 0: stop */
++      break;
+     const int c2 = base64val(buf[1]);
++    if (c2 == -1) /* '=' at slot 1: invalid padding, stop */
++      break;
+ 
+     /* first char */
+     ch = (c1 << 2) | (c2 >> 4);
diff --git a/date-tm_mon-bound.patch b/date-tm_mon-bound.patch
new file mode 100644
index 0000000..c901800
--- /dev/null
+++ b/date-tm_mon-bound.patch
@@ -0,0 +1,23 @@
+From d50e464a34045e1ab84a3be92437691d3790d970 Mon Sep 17 00:00:00 2001
+From: Syed Mohammed Nayyar <jmestwa at gmail.com>
+Date: Thu, 2 Jul 2026 16:15:49 +0530
+Subject: [PATCH 09/10] date: bound tm_mon in mutt_date_make_time
+
+(cherry picked from commit 993c8b6dc7f1791f13bc4fd2c1bb83b94c76e81e)
+---
+ mutt/date.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/mutt/date.c b/mutt/date.c
+index 2d16489..eef7510 100644
+--- a/mutt/date.c
++++ b/mutt/date.c
+@@ -255,6 +255,8 @@ time_t mutt_date_make_time(struct tm *t, bool local)
+ 
+   if ((t->tm_mday < 1) || (t->tm_mday > 31))
+     return TIME_T_MIN;
++  if ((t->tm_mon < 0) || (t->tm_mon > 11))
++    return TIME_T_MIN;
+   if ((t->tm_hour < 0) || (t->tm_hour > 23) || (t->tm_min < 0) ||
+       (t->tm_min > 59) || (t->tm_sec < 0) || (t->tm_sec > 60))
+   {
diff --git a/expando-justify-overrun.patch b/expando-justify-overrun.patch
new file mode 100644
index 0000000..223ad66
--- /dev/null
+++ b/expando-justify-overrun.patch
@@ -0,0 +1,75 @@
+From a51ab1efb422a1253c068bb0f0033547b2e08f20 Mon Sep 17 00:00:00 2001
+From: Richard Russon <rich at flatcap.org>
+Date: Thu, 13 Aug 2026 08:44:19 +0100
+Subject: [PATCH 10/10] expando: fix buf_justify buffer overrun
+
+Avoid writing past the end of the destination buffer when
+right/center justifying by moving the terminating NUL with the
+payload and allocating exactly the required final size.
+
+Add regression coverage for empty-string padding cases that
+previously exercised the overrun path.
+
+(cherry picked from commit 550ac6cc6e4916bf8c7bc493cc80ac2cde1e8a0b)
+---
+ expando/format.c | 23 +++++++++++------------
+ 1 file changed, 11 insertions(+), 12 deletions(-)
+
+diff --git a/expando/format.c b/expando/format.c
+index 45d23f1..0978270 100644
+--- a/expando/format.c
++++ b/expando/format.c
+@@ -51,42 +51,41 @@ void buf_justify(struct Buffer *buf, enum FormatJustify justify, size_t max_cols
+   if (!buf || (pad_char == '\0'))
+     return;
+ 
+-  size_t len = buf_len(buf);
++  const size_t len = buf_len(buf);
+   if (len >= max_cols)
+     return;
+ 
+-  buf_alloc(buf, len + max_cols);
+-
+-  max_cols -= len;
++  const size_t pad = max_cols - len;
++  buf_alloc(buf, max_cols + 1);
+ 
+   switch (justify)
+   {
+     case JUSTIFY_LEFT:
+     {
+-      memset(buf->dptr, pad_char, max_cols);
++      memset(buf->dptr, pad_char, pad);
+       break;
+     }
+ 
+     case JUSTIFY_CENTER:
+     {
+-      if (max_cols > 1)
++      if (pad > 1)
+       {
+-        memmove(buf->data + (max_cols / 2), buf->data, len);
+-        memset(buf->data, pad_char, max_cols / 2);
++        memmove(buf->data + (pad / 2), buf->data, len + 1);
++        memset(buf->data, pad_char, pad / 2);
+       }
+-      memset(buf->data + len + (max_cols / 2), pad_char, (max_cols + 1) / 2);
++      memset(buf->data + len + (pad / 2), pad_char, (pad + 1) / 2);
+       break;
+     }
+ 
+     case JUSTIFY_RIGHT:
+     {
+-      memmove(buf->data + max_cols, buf->data, len);
+-      memset(buf->data, pad_char, max_cols);
++      memmove(buf->data + pad, buf->data, len + 1);
++      memset(buf->data, pad_char, pad);
+       break;
+     }
+   }
+ 
+-  buf->dptr += max_cols;
++  buf->dptr += pad;
+   buf->dptr[0] = '\0';
+ }
+ 
diff --git a/imap-cram-challenge-oob.patch b/imap-cram-challenge-oob.patch
new file mode 100644
index 0000000..5e8de03
--- /dev/null
+++ b/imap-cram-challenge-oob.patch
@@ -0,0 +1,30 @@
+From 417f3dc727d800d44ed6f2dc46c5c80543531324 Mon Sep 17 00:00:00 2001
+From: Syed Mohammed Nayyar <jmestwa at gmail.com>
+Date: Wed, 1 Jul 2026 15:01:36 +0530
+Subject: [PATCH 02/10] auth_cram: fix out-of-bounds read of cram-md5 challenge
+
+(cherry picked from commit 6c31d8a512ba529b3a6f6f0836a2039e58ff2d0b)
+---
+ imap/auth_cram.c | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/imap/auth_cram.c b/imap/auth_cram.c
+index 532f937..c849312 100644
+--- a/imap/auth_cram.c
++++ b/imap/auth_cram.c
+@@ -131,11 +131,14 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapAccountData *adata, const char *m
+     goto bail;
+   }
+ 
+-  if (mutt_b64_decode(adata->buf + 2, obuf->data, obuf->dsize) == -1)
++  int dlen = mutt_b64_decode(adata->buf + 2, obuf->data, obuf->dsize - 1);
++  if (dlen == -1)
+   {
+     mutt_debug(LL_DEBUG1, "Error decoding base64 response\n");
+     goto bail;
+   }
++  obuf->data[dlen] = '\0';
++  buf_fix_dptr(obuf);
+ 
+   mutt_debug(LL_DEBUG2, "CRAM challenge: %s\n", buf_string(obuf));
+ 
diff --git a/imap-cram-md5-key.patch b/imap-cram-md5-key.patch
new file mode 100644
index 0000000..68e4842
--- /dev/null
+++ b/imap-cram-md5-key.patch
@@ -0,0 +1,32 @@
+From 20027d74f2db3bb0e2d967b51adb4a705c929037 Mon Sep 17 00:00:00 2001
+From: Richard Russon <rich at flatcap.org>
+Date: Mon, 2 Mar 2026 23:42:08 +0000
+Subject: [PATCH 03/10] imap: use memcpy for binary MD5 hash in CRAM-MD5
+ hmac_md5()
+
+mutt_str_copy() uses strlcpy internally which stops at the first NUL
+byte. An MD5 digest is 16 bytes of binary data with ~99.6% probability
+of containing at least one NUL. For passwords longer than 64 bytes,
+the MD5 hash of the password is used as the HMAC key, but the string
+copy silently truncated it at the first NUL, weakening the key.
+
+Use memcpy() to copy the full binary digest.
+
+(cherry picked from commit ddae337e84a728be432d061e253c5a1092347ca1)
+---
+ imap/auth_cram.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/imap/auth_cram.c b/imap/auth_cram.c
+index c849312..58c7853 100644
+--- a/imap/auth_cram.c
++++ b/imap/auth_cram.c
+@@ -60,7 +60,7 @@ static void hmac_md5(const char *password, const char *challenge, unsigned char
+   {
+     unsigned char hash_passwd[MD5_DIGEST_LEN];
+     mutt_md5_bytes(password, secret_len, hash_passwd);
+-    mutt_str_copy((char *) secret, (char *) hash_passwd, MD5_DIGEST_LEN);
++    memcpy(secret, hash_passwd, MD5_DIGEST_LEN);
+     secret_len = MD5_DIGEST_LEN;
+   }
+   else
diff --git a/imap-status-literal.patch b/imap-status-literal.patch
new file mode 100644
index 0000000..8891069
--- /dev/null
+++ b/imap-status-literal.patch
@@ -0,0 +1,39 @@
+From 0acb4310b3e861d19472be5587069f62766143a6 Mon Sep 17 00:00:00 2001
+From: jmestwa-coder <jmestwa at gmail.com>
+Date: Tue, 13 Oct 2026 13:16:17 +0530
+Subject: [PATCH 04/10] imap: bound STATUS mailbox literal read in
+ cmd_parse_status (#5045)
+
+cmd_parse_status() advances past a STATUS mailbox name sent as an IMAP
+literal with `s = mailbox + litlen; s[0] = 0; s++; SKIPWS(s)`, even when
+the literal exactly fills the continuation line. A server that sends the
+mailbox name with no trailing ` (items)` makes the read step past the end
+of the response, so the following `(` check and item loop parse leftover
+bytes of the reused buffer as STATUS values. Guard the advance like the
+sibling cmd_parse_list() already does.
+
+(cherry picked from commit 8793720ddf1c7cfc190378c41b89daa67a6d7d45)
+---
+ imap/command.c | 9 ++++++---
+ 1 file changed, 6 insertions(+), 3 deletions(-)
+
+diff --git a/imap/command.c b/imap/command.c
+index 3d992c4..0d0b135 100644
+--- a/imap/command.c
++++ b/imap/command.c
+@@ -923,9 +923,12 @@ static void cmd_parse_status(struct ImapAccountData *adata, char *s)
+ 
+     mailbox = adata->buf;
+     s = mailbox + litlen;
+-    s[0] = '\0';
+-    s++;
+-    SKIPWS(s);
++    if (s[0] != '\0')
++    {
++      s[0] = '\0';
++      s++;
++      SKIPWS(s);
++    }
+   }
+   else
+   {
diff --git a/imap-utf7-oob.patch b/imap-utf7-oob.patch
new file mode 100644
index 0000000..1b3f8e7
--- /dev/null
+++ b/imap-utf7-oob.patch
@@ -0,0 +1,33 @@
+From 46df3139dbd2411886f6cd120e1221622f39e1e3 Mon Sep 17 00:00:00 2001
+From: jmestwa-coder <jmestwa at gmail.com>
+Date: Tue, 13 Oct 2026 13:07:42 +0530
+Subject: [PATCH 05/10] imap: fix out-of-bounds read in utf8_to_utf7 (#5047)
+
+The decoder accepts the obsolete 5- and 6-byte UTF-8 forms, so ch can
+exceed U+10FFFF. Anything over 0xffff is then encoded as a UTF-16
+surrogate pair, pair1 = 0xd800 + (ch >> 10), which leaves 16 bits and
+makes the unmasked B64Chars[b | pair1 >> k] lookup index past the end of
+the 64-byte table. Bound the code point with the other malformed-input
+rejections.
+
+(cherry picked from commit bab0d41b3c14861a18cca5eeae86a1d31f387bc2)
+---
+ imap/utf7.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/imap/utf7.c b/imap/utf7.c
+index 94765ff..51d403a 100644
+--- a/imap/utf7.c
++++ b/imap/utf7.c
+@@ -315,6 +315,11 @@ static char *utf8_to_utf7(const char *u8, size_t u8len, char **u7, size_t *u7len
+     }
+     if ((n > 1) && !(ch >> (n * 5 + 1)))
+       goto bail;
++    if (ch > 0x10ffff)
++    {
++      /* Outside Unicode, so it has no UTF-16 representation */
++      goto bail;
++    }
+     u8 += n;
+     u8len -= n;
+ 
diff --git a/nntp-overview-fmt-oob.patch b/nntp-overview-fmt-oob.patch
new file mode 100644
index 0000000..43dda10
--- /dev/null
+++ b/nntp-overview-fmt-oob.patch
@@ -0,0 +1,47 @@
+From 988af934970554717afb5e76ec6f7d549c13b006 Mon Sep 17 00:00:00 2001
+From: jmestwa-coder <jmestwa at gmail.com>
+Date: Wed, 14 Oct 2026 11:36:18 +0530
+Subject: [PATCH 06/10] nntp: fix out-of-bounds read of truncated overview
+ format (#5044)
+
+(cherry picked from commit fd8572afc9201ed52a7e6ab9895ff6397bdde475)
+---
+ nntp/nntp.c | 18 +++++++++---------
+ 1 file changed, 9 insertions(+), 9 deletions(-)
+
+diff --git a/nntp/nntp.c b/nntp/nntp.c
+index 864ef1c..5d0213d 100644
+--- a/nntp/nntp.c
++++ b/nntp/nntp.c
+@@ -76,14 +76,14 @@ struct stat;
+ struct NntpAccountData *CurrentNewsSrv = NULL;
+ 
+ /// Fields to get from server, if it supports the LIST OVERVIEW.FMT feature
+-static const char *OverviewFmt = "Subject:\0"
+-                                 "From:\0"
+-                                 "Date:\0"
+-                                 "Message-ID:\0"
+-                                 "References:\0"
+-                                 "Content-Length:\0"
+-                                 "Lines:\0"
+-                                 "\0";
++static const char OverviewFmt[] = "Subject:\0"
++                                  "From:\0"
++                                  "Date:\0"
++                                  "Message-ID:\0"
++                                  "References:\0"
++                                  "Content-Length:\0"
++                                  "Lines:\0"
++                                  "\0";
+ 
+ /**
+  * struct FetchCtx - Keep track when getting data from a server
+@@ -332,7 +332,7 @@ static int nntp_attempt_features(struct NntpAccountData *adata)
+     }
+     if (!mutt_str_startswith(buf, "215"))
+     {
+-      adata->overview_fmt = mutt_str_dup(OverviewFmt);
++      adata->overview_fmt = mutt_strn_dup(OverviewFmt, sizeof(OverviewFmt));
+     }
+     else
+     {
diff --git a/parse-references-oob.patch b/parse-references-oob.patch
new file mode 100644
index 0000000..863378c
--- /dev/null
+++ b/parse-references-oob.patch
@@ -0,0 +1,126 @@
+From ba0299a8b52e51af1f18c25fc9bef8b3a2582ac2 Mon Sep 17 00:00:00 2001
+From: Syed Mohammed Nayyar <jmestwa at gmail.com>
+Date: Sat, 4 Jul 2026 00:21:21 +0530
+Subject: [PATCH 07/10] parse: fix out-of-bounds read in parse_references
+
+mutt_extract_message_id() reports the message-id offset within the
+rfc2047-decoded copy, but parse_references() advances the raw header by
+it. An encoded-word in a charset that expands to UTF-8 makes the decoded
+text longer, so the read pointer walks past the header buffer. Decode
+the header once and iterate over that copy.
+
+(cherry picked from commit 8f6e808c06674a4e6f21162f899716ce6377fe7e)
+---
+ email/parse.c | 72 +++++++++++++++++++++++++++++++++++++--------------
+ 1 file changed, 52 insertions(+), 20 deletions(-)
+
+diff --git a/email/parse.c b/email/parse.c
+index 09b7aad..f1d6ee0 100644
+--- a/email/parse.c
++++ b/email/parse.c
+@@ -314,6 +314,43 @@ static void parse_content_disposition(const char *s, struct Body *b)
+   }
+ }
+ 
++/**
++ * extract_message_id - Find a message-id in a string
++ * @param[in]  s   String to parse
++ * @param[out] len Number of bytes of s parsed (optional)
++ * @retval ptr  Message id found
++ * @retval NULL No more message ids
++ *
++ * @a len is an offset into @a s, so the caller may advance @a s by it to find
++ * the next message-id.  The string is scanned verbatim; decoding, if any, is
++ * the caller's responsibility.
++ *
++ * @note Caller must free returned string
++ */
++static char *extract_message_id(const char *s, size_t *len)
++{
++  if (!s)
++    return NULL;
++
++  for (const char *p = s, *beg = NULL; *p; p++)
++  {
++    if (*p == '<')
++    {
++      beg = p;
++      continue;
++    }
++
++    if (beg && (*p == '>'))
++    {
++      if (len)
++        *len = p - s + 1;
++      return mutt_strn_dup(beg, (p + 1) - beg);
++    }
++  }
++
++  return NULL;
++}
++
+ /**
+  * parse_references - Parse references from an email header
+  * @param head List to receive the references
+@@ -324,11 +361,21 @@ static void parse_references(struct ListHead *head, const char *s)
+   if (!head)
+     return;
+ 
++  /* Decode once: mutt_extract_message_id() returns an offset into the decoded
++   * text, so the search and the advance must happen on the same string.
++   * Decoding can lengthen the text (e.g. a single-byte charset expanding to
++   * UTF-8), so applying that offset to the raw header would run off the end. */
++  char *decoded = mutt_str_dup(s);
++  rfc2047_decode(&decoded);
++
+   char *m = NULL;
+-  for (size_t off = 0; (m = mutt_extract_message_id(s, &off)); s += off)
++  const char *p = decoded;
++  for (size_t off = 0; (m = extract_message_id(p, &off)); p += off)
+   {
+     mutt_list_insert_head(head, m);
+   }
++
++  FREE(&decoded);
+ }
+ 
+ /**
+@@ -393,9 +440,11 @@ enum ContentType mutt_check_mime_type(const char *s)
+ /**
+  * mutt_extract_message_id - Find a message-id
+  * @param[in]  s String to parse
+- * @param[out] len Number of bytes of s parsed
++ * @param[out] len Number of bytes of s parsed (optional)
+  * @retval ptr  Message id found
+  * @retval NULL No more message ids
++ *
++ * @note Caller must free returned string
+  */
+ char *mutt_extract_message_id(const char *s, size_t *len)
+ {
+@@ -405,24 +454,7 @@ char *mutt_extract_message_id(const char *s, size_t *len)
+   char *decoded = mutt_str_dup(s);
+   rfc2047_decode(&decoded);
+ 
+-  char *res = NULL;
+-
+-  for (const char *p = decoded, *beg = NULL; *p; p++)
+-  {
+-    if (*p == '<')
+-    {
+-      beg = p;
+-      continue;
+-    }
+-
+-    if (beg && (*p == '>'))
+-    {
+-      if (len)
+-        *len = p - decoded + 1;
+-      res = mutt_strn_dup(beg, (p + 1) - beg);
+-      break;
+-    }
+-  }
++  char *res = extract_message_id(decoded, len);
+ 
+   FREE(&decoded);
+   return res;
diff --git a/thread-dangling-pointers.patch b/thread-dangling-pointers.patch
new file mode 100644
index 0000000..b68db4b
--- /dev/null
+++ b/thread-dangling-pointers.patch
@@ -0,0 +1,60 @@
+From ef5c867de800f1317fa2b4440550233cf0c941ae Mon Sep 17 00:00:00 2001
+From: Richard Russon <rich at flatcap.org>
+Date: Mon, 6 Jul 2026 10:44:53 +0100
+Subject: [PATCH 01/10] mutt_thread: fix crash from dangling Email->thread
+ pointers
+
+mutt_messages_in_thread() crashed in the pager while rendering the
+thread-position expando (%n) because e->thread pointed at a MuttThread
+node that had already been freed.
+
+Root cause: mutt_clear_threads() walked m->emails[] but bailed out with
+'break' on the first NULL slot before freeing the thread nodes.  A NULL
+hole in the middle of the array (partial read, or an expunged message)
+therefore left every following Email with its ->thread pointer intact
+while mutt_hash_free() freed the nodes underneath them.  Any surviving
+reference to such an Email (e.g. the pager's shared email) then held a
+dangling ->thread pointer.
+
+Fix by clearing every non-NULL Email instead of stopping at the first
+hole.  Also harden mutt_messages_in_thread() to guard its tree-walk
+loops against NULL nodes/messages and bail out safely rather than
+dereferencing them.
+
+(cherry picked from commit b39d9d9e503d8e5ebac1f1ffe43cbdc7f43be156)
+---
+ mutt_thread.c | 13 +++++++++++--
+ 1 file changed, 11 insertions(+), 2 deletions(-)
+
+diff --git a/mutt_thread.c b/mutt_thread.c
+index 51f00e8..eaadf69 100644
+--- a/mutt_thread.c
++++ b/mutt_thread.c
+@@ -808,7 +808,10 @@ void mutt_clear_threads(struct ThreadsContext *tctx)
+   {
+     struct Email *e = m->emails[i];
+     if (!e)
+-      break;
++    {
++      // Keep processing, in case there are other holes in the Email array
++      continue;
++    }
+ 
+     /* mailbox may have been only partially read */
+     e->thread = NULL;
+@@ -1750,8 +1753,14 @@ int mutt_messages_in_thread(struct Mailbox *m, struct Email *e, enum MessageInTh
+ 
+   for (int i = 0; i < (((mit == MIT_POSITION) || !threads[1]) ? 1 : 2); i++)
+   {
+-    while (!threads[i]->message)
++    /* Descend to the first node that references a real Email.
++     * Guard against a malformed or partially-built tree:
++     * a node with no message and no child would otherwise cause a NULL dereference. */
++    while (threads[i] && !threads[i]->message)
+       threads[i] = threads[i]->child;
++
++    if (!threads[i] || !threads[i]->message)
++      return 1;
+   }
+ 
+   if (threaded == UT_REVERSE)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/neomutt.git/commitdiff/0a58e0d8f81914bef2ff0913f1bc364609547eca



More information about the pld-cvs-commit mailing list