unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Matt Armstrong <marmstrong@google.com>
To: notmuch@notmuchmail.org
Subject: bug: notmuch show --decrypt leads to SIGSEGV
Date: Tue, 15 Aug 2017 10:37:31 -0700	[thread overview]
Message-ID: <qf5d17wzq90.fsf@google.com> (raw)

I've been able to diagnose a SIGSEGV, and I have a workaround that
satisfies me.  I'm unsure how to fix it, so I'll describe the problem
and leave it at that.

Repro:

% notmuch --version
notmuch 0.25+22~g0967e46 (a recent git @HEAD)
% notmuch show --format=sexp --decrypt thread:000000000002ad2c
-> SIGSEGV

Workaround:

Don't pass --decrypt.  In Emacs, configure notmuch-crypto-process-mime
to shut off crypto processing, or C-u before in notmuch-show before
viewing a problematic thread.

Diagnosis:

mime-node.c's _mime_node_create() can return NULL in various scenarios
yet few to none of its callers appear to handle it properly.  In this
particular case, the NULL is returned here:

#if (GMIME_MAJOR_VERSION < 3)
    if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
	|| (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
	GMimeContentType *content_type = g_mime_object_get_content_type (part);
	const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
	cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
	if (!cryptoctx) {
	    return NULL;
	}
    }
#endif

Note above a missing call to talloc_free(node) before the return, which
suggests a kind of bit-rot has set in for the GMIME_MAJOR_VERSION<3
case?  Anyway...

mime_node_child() calls _mime_node_create() and will SIGSEGV:

    node = _mime_node_create (parent, sub);

    if (child == parent->next_child && parent->next_part_num != -1) {
	/* We're traversing in depth-first order.  Record the child's
	 * depth-first numbering. */
	node->part_num = parent->next_part_num;
	node->next_part_num = node->part_num + 1;


If I address that by returning NULL from mime_node_child() when
_mime_node_create() does, then the problem cascades to callers.  None of
the callers of mime_node_child() explicitly handle the NULL return case:

mime-node.c:		mime_node_t *child = mime_node_child (node, i);
notmuch-show.c:571:	format_part_text (ctx, sp, mime_node_child (node, i), indent, params);
notmuch-show.c:622:	    format_part_sprinter (ctx, sp, mime_node_child (node, 0), first, TRUE, include_html);
notmuch-show.c:724:	format_part_sprinter (ctx, sp, mime_node_child (node, i), i == 0, TRUE, include_html);

..._mime_node_seek_dfs_walk will proceed to SIGSEGV, and so will
format_part_...().

         reply	other threads:[~2017-08-15 17:37 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 13:31 [PATCH] crypto: gracefully handle gmime errors Jan Malakhovski
2017-08-31 13:44 ` Jan Malakhovski
2017-09-01  0:10   ` [PATCH] cli: propagate NULL from _mime_node_create, handle it in callers David Bremner
2017-09-01 20:32     ` Jan Malakhovski
2017-08-31 14:22 ` [PATCH] crypto: gracefully handle gmime errors David Bremner
2017-08-31 14:30   ` David Bremner
2017-08-15 17:37     ` Matt Armstrong [this message]
2017-08-15 18:11       ` bug: notmuch show --decrypt leads to SIGSEGV David Bremner
2017-08-15 19:10         ` Matt Armstrong
2017-08-15 23:12           ` David Bremner
2017-08-16 16:41             ` Matt Armstrong
2017-08-20 13:43               ` David Bremner
2017-08-31 15:17       ` [PATCH] crypto: gracefully handle gmime errors Jan Malakhovski
2017-08-31 18:33         ` David Bremner
2017-08-31 22:27         ` David Bremner
2017-08-31 23:20           ` Matt Armstrong
2017-08-31 23:59           ` Jan Malakhovski
2017-11-10  1:05       ` bug: notmuch show --decrypt leads to SIGSEGV David Bremner
2017-08-31 14:34 ` [BUG] gmime-3.0.1 (was: [PATCH] crypto: gracefully handle gmime errors) Jan Malakhovski
2017-09-05 10:54   ` David Bremner
2017-09-05 12:55     ` Jan Malakhovski
2017-09-05 13:38       ` David Bremner
2017-09-05 14:26         ` Jan Malakhovski
2017-09-05 15:26           ` David Bremner
2017-09-05 20:23             ` Jan Malakhovski
2017-09-05 14:04       ` Servilio Afre Puentes
2017-09-05 14:27         ` Jan Malakhovski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=qf5d17wzq90.fsf@google.com \
    --to=marmstrong@google.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).