X-Envelope-From: notmuch-bounces@notmuchmail.org  Mon Aug 10 23:40:37 2026
Return-Path: <notmuch-bounces@notmuchmail.org>
X-Original-To: nmbug@yantan.tethera.net
Delivered-To: nmbug@yantan.tethera.net
Received: from yantan.tethera.net (localhost [127.0.0.1])
	by mail.notmuchmail.org (Postfix) with ESMTP id AB98C5F874;
	Mon, 10 Aug 2026 23:40:37 +0000 (UTC)
Received: from phubs.tethera.net (phubs.tethera.net [192.99.9.157])
	by mail.notmuchmail.org (Postfix) with ESMTPS id 779655F5B2
	for <notmuch@notmuchmail.org>; Mon, 10 Aug 2026 23:40:33 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tethera.net;
 i=@tethera.net; q=dns/txt; s=2024; t=1786404779; h=from : to : subject
 : date : message-id : in-reply-to : references : mime-version :
 content-transfer-encoding : from;
 bh=Rbg99z6te+kiDeTPSjl7NKxAX/WllYzomEe4CvY0tsU=;
 b=jBSALRdvS1QRnOrOZ/GDXtgx9eSoyZT1sYUzrB0vzuwiTLoJo3BYTK/3GhJsOC4HroXjn
 oMs6e4UPhoxWXczgpqoN3CbklHFlNjw2B7QHhvyubqtKyXIuNzLeW9qtEAcVMxtkYMj/hsy
 YZDUVkS6u0420NoHzddaNRDB0YlTFh31LW+eJ6bGre+qZM5vY1cEFm44vt4koTC+JpWrX2q
 iSdlXJnsjfnm9cPOtEdYJXgw8skj6Crn5O06SxuIh5QYeTKV9XiXohqSS73ISzAGjlTAtvb
 1H6eIbo2MfZRBWRinbeW9SxIkuq086tldbYcHtVIziKIdoVHXHMM+/l3I7zg==
Received: from tethera.net (fctnnbsc38w-142-162-53-181.dhcp-dynamic.fibreop.nb.bellaliant.net [142.162.53.181])
	by phubs.tethera.net (Postfix) with ESMTPS id 1B3A21800F8;
	Mon, 10 Aug 2026 20:32:59 -0300 (ADT)
Received: (nullmailer pid 1965843 invoked by uid 1000);
	Mon, 10 Aug 2026 23:32:53 -0000
From: David Bremner <david@tethera.net>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: [PATCH 3/3] cli/show: handle NULL returns from mime_node_child
Date: Mon, 10 Aug 2026 20:32:36 -0300
Message-ID: <20260810233236.1965808-3-david@tethera.net>
X-Mailer: git-send-email 2.53.0
In-Reply-To: <20260810233236.1965808-1-david@tethera.net>
References: <87o6fe9fsf.fsf@tethera.net>
 <20260810233236.1965808-1-david@tethera.net>
MIME-Version: 1.0
Message-ID-Hash: RGBN33PMTCQ3YBEVDVJIBOWLZYU625XZ
X-Message-ID-Hash: RGBN33PMTCQ3YBEVDVJIBOWLZYU625XZ
X-MailFrom: bremner@tethera.net
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
X-Mailman-Version: 3.3.3
Precedence: list
List-Id: "Use and development of the notmuch mail system." <notmuch.notmuchmail.org>
List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
List-Owner: <mailto:notmuch-owner@notmuchmail.org>
List-Post: <mailto:notmuch@notmuchmail.org>
List-Subscribe: <mailto:notmuch-join@notmuchmail.org>
List-Unsubscribe: <mailto:notmuch-leave@notmuchmail.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

mime_node_child has (potentially) returned NULL since it was
introduced, but apparently this did not happen much in practice, since
nobody mentioned segfaults.  Clean that up so that at least notmuch
show does not segfault with empty message attachments anymore [1].

At least in the test case [2], this seems to produce structured output
(json / sexpr) conforming to devel/schemata, since a multipart/* can
have 0 or more children under the 'content' key.

[1] id:20260623074714Z.449345370-stepnem@smrk.net
[2] id:1782193672-98446-mlmmj-36f22ff2@FreeBSD.org
---
 notmuch-show.c    | 27 ++++++++++++++++++---------
 test/T520-show.sh |  1 -
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 8c23f821..22983101 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -637,9 +637,11 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 	}
     }
 
-    for (i = 0; i < node->nchildren; i++)
-	format_part_text (ctx, sp, mime_node_child (node, i), indent, params);
-
+    for (i = 0; i < node->nchildren; i++) {
+	mime_node_t *child = mime_node_child (node, i);
+	if (child != NULL)
+	    format_part_text (ctx, sp, child, indent, params);
+    }
     if (GMIME_IS_MESSAGE (node->part))
 	g_mime_stream_printf (stream, "\fbody}\n");
 
@@ -689,10 +691,13 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
 	sp->integer (sp, duplicate > 0 ? duplicate : 1);
 
 	if (output_body) {
-	    sp->map_key (sp, "body");
-	    sp->begin_list (sp);
-	    format_part_sprinter (ctx, sp, mime_node_child (node, 0), -1, true, include_html);
-	    sp->end (sp);
+	    mime_node_t *child = mime_node_child (node, 0);
+	    if (child) {
+		sp->map_key (sp, "body");
+		sp->begin_list (sp);
+		format_part_sprinter (ctx, sp, child, -1, true, include_html);
+		sp->end (sp);
+	    }
 	}
 
 	msg_crypto = mime_node_get_message_crypto_status (node);
@@ -854,8 +859,12 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
 	nclose = 3;
     }
 
-    for (i = 0; i < node->nchildren; i++)
-	format_part_sprinter (ctx, sp, mime_node_child (node, i), -1, true, include_html);
+    for (i = 0; i < node->nchildren; i++) {
+	mime_node_t *child = mime_node_child (node, i);
+	if (child) {
+	    format_part_sprinter (ctx, sp, child, -1, true, include_html);
+	}
+    }
 
     /* Close content structures */
     for (i = 0; i < nclose; i++)
diff --git a/test/T520-show.sh b/test/T520-show.sh
index 9eb49284..25afded7 100755
--- a/test/T520-show.sh
+++ b/test/T520-show.sh
@@ -109,7 +109,6 @@ done
 add_email_corpus broken
 for format in text json sexp; do
     test_begin_subtest "don't crash on empty part ($format)"
-    test_subtest_known_broken
     test_expect_code 0 "notmuch show --format=$format id:1782193672-98446-mlmmj-36f22ff2@FreeBSD.org"
 done
 
-- 
2.53.0

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org
