From: Austin Clements <amdragon@MIT.EDU>
To: Mark Walters <markwalters1009@gmail.com>,
Ben Gamari <bgamari.foss@gmail.com>,
notmuch@notmuchmail.org
Subject: Re: [PATCH] sprinters: bugfix when NULL passed for a string.
Date: Tue, 07 Aug 2012 22:09:35 -0400 [thread overview]
Message-ID: <87ipcut9r4.fsf@awakening.csail.mit.edu> (raw)
In-Reply-To: <874noe1o0r.fsf@qmul.ac.uk>
LGTM.
This won't commute with [0], since that introduces broken tests that are
fixed by this patch.
I think we should remove the fields in the JSON header object for
missing headers (except perhaps From and Date, if those really are
mandatory headers), but I think we should do that after the freeze,
since it might affect frontends. It probably makes sense to add an
Emacs test or two to the tests in [0].
[0] id:"1344389313-7886-1-git-send-email-amdragon@mit.edu"
On Tue, 07 Aug 2012, Mark Walters <markwalters1009@gmail.com> wrote:
> The string function in a sprinter may be called with a NULL string
> pointer (eg if a header is absent). This causes a segfault. We fix
> this by checking for a null pointer in the string functions and update
> the sprinter documentation.
>
> At the moment some output when format=text is done directly rather than
> via an sprinter: in that case a null pointer is passed to printf or
> similar and a "(null)" appears in the output. That behaviour is not
> changed in this patch.
> ---
>
> This could really do with some tests (it is the second time this type of
> bug has occurred). To be considered as a message by notmuch new a file
> needs at least one of a From: Subject: or To: header. Thus we should
> have three messages each of which just contains that single header (and
> nothing else) and check that search and show work as expected.
>
>
>
> sprinter-json.c | 2 ++
> sprinter-text.c | 2 ++
> sprinter.h | 4 +++-
> 3 files changed, 7 insertions(+), 1 deletions(-)
>
> 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));
> }
>
> diff --git a/sprinter-text.c b/sprinter-text.c
> index dfa54b5..10343be 100644
> --- a/sprinter-text.c
> +++ b/sprinter-text.c
> @@ -38,6 +38,8 @@ text_string_len (struct sprinter *sp, const char *val, size_t len)
> static void
> text_string (struct sprinter *sp, const char *val)
> {
> + if (val == NULL)
> + val = "";
> text_string_len (sp, val, strlen (val));
> }
>
> diff --git a/sprinter.h b/sprinter.h
> index 5f43175..912a526 100644
> --- a/sprinter.h
> +++ b/sprinter.h
> @@ -27,7 +27,9 @@ typedef struct sprinter {
> * a list or map, followed or preceded by separators). For string
> * and string_len, the char * must be UTF-8 encoded. string_len
> * allows non-terminated strings and strings with embedded NULs
> - * (though the handling of the latter is format-dependent).
> + * (though the handling of the latter is format-dependent). For
> + * string (but not string_len) the string pointer passed may be
> + * NULL.
> */
> void (*string) (struct sprinter *, const char *);
> void (*string_len) (struct sprinter *, const char *, size_t);
> --
> 1.7.9.1
>
>
> H
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
next prev parent reply other threads:[~2012-08-08 2:09 UTC|newest]
Thread overview: 12+ 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
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 [this message]
2012-08-08 7:31 ` Mark Walters
2012-08-08 16:25 ` Jameson Graef Rollins
-- strict thread matches above, loose matches on Subject: below --
2012-08-07 21:21 [PATCH] test: Add test for messages with missing headers Austin Clements
2012-08-08 1:28 ` [PATCH v2] " Austin Clements
2012-08-08 21:23 ` [PATCH] sprinters: bugfix when NULL passed for a string Mark Walters
2012-08-08 21:28 ` Austin Clements
2012-08-12 19:51 ` David Bremner
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=87ipcut9r4.fsf@awakening.csail.mit.edu \
--to=amdragon@mit.edu \
--cc=bgamari.foss@gmail.com \
--cc=markwalters1009@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).