From: Mark Walters <markwalters1009@gmail.com>
To: Ben Gamari <bgamari.foss@gmail.com>, notmuch@notmuchmail.org
Subject: Re: Segmentation fault in notmuch search --format=json
Date: Tue, 07 Aug 2012 08:07:14 +0100 [thread overview]
Message-ID: <878vdrp4d9.fsf@qmul.ac.uk> (raw)
In-Reply-To: <871ujjuu2z.fsf@gmail.com>
On Tue, 07 Aug 2012, Ben Gamari <bgamari.foss@gmail.com> wrote:
> It seems some messages trigger a segmentation fault in
> `do_search_threads()`. It appears the problem occurs (at least) when
> `authors` is NULL.
Hi thanks for the bug report and detailed debugging. I think I can see
the problem and there is a test patch to fix it below, and this does
appear to be a regression.
In json.c the function json_quote_str explicitly checks/allows for a
NULL pointer passed as a string and pretends it is just an empty
string. That behaviour was lost in the move to structured formatters.
A simple fix is to put this check for a null pointer in json_string in
sprinter-json.c which is what this patch does.
Incidentally this is the second time this bug has appeared:
commit cacefbf3d6dd5bce0b60b3cdfce29bfa371dfaea
Author: David Edmondson <dme@dme.org>
Date: Tue Apr 6 08:24:00 2010 +0100
json: Avoid calling strlen(NULL)
MIME parts may have no filename, which previously resulted in calling
strlen(NULL).
so it really might be worth having a test for it!
Finally, I think nothing in json.c is used anymore so perhaps it
could be removed.
diff --git a/sprinter-json.c b/sprinter-json.c
index c9b6835..0a07790 100644
--- a/sprinter-json.c
+++ b/sprinter-json.c
@@ -118,6 +118,8 @@ json_string_len (struct sprinter *sp, const char *val, size_t len)
static void
json_string (struct sprinter *sp, const char *val)
{
+ if (val == NULL)
+ val = "";
json_string_len (sp, val, strlen (val));
}
next prev parent reply other threads:[~2012-08-07 7:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-07 5:52 Segmentation fault in notmuch search --format=json Ben Gamari
2012-08-07 7:07 ` Mark Walters [this message]
2012-08-07 8:08 ` Jameson Graef Rollins
2012-08-07 12:49 ` Austin Clements
2012-08-07 19:48 ` [PATCH] sprinters: bugfix when NULL passed for a string Mark Walters
2012-08-08 1:36 ` Jameson Graef Rollins
2012-08-08 2:09 ` Austin Clements
2012-08-08 7:31 ` Mark Walters
2012-08-08 16:25 ` Jameson Graef Rollins
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=878vdrp4d9.fsf@qmul.ac.uk \
--to=markwalters1009@gmail.com \
--cc=bgamari.foss@gmail.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).