Re: [PATCH] sprinters: bugfix when NULL passed for a string.

Subject: Re: [PATCH] sprinters: bugfix when NULL passed for a string.

Date: Tue, 07 Aug 2012 18:36:20 -0700

To: Mark Walters, Ben Gamari, notmuch@notmuchmail.org

Cc:

From: Jameson Graef Rollins


On Tue, Aug 07 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. 

Hey, Mark.  Thanks for working on this.

I was wondering if we should distinguish between the header being
absent, and having a null value.  It looks like the idea here is to
output an empty string for the value in all of these cases.  But should
we output the field at all if the actual header isn't there?  In other
words, I can imagine three scenarios:

Header: value
Header:        --> "Header": ""
no header     

At the moment these would be output as:

"Header": "value"
"Header": ""
"Header": ""

Where as I could imagine we could instead do:

"Header": "value"
"Header": ""
no output

Maybe that would be too complicated or break the output spec to much?
If it's too complicated to do the later, then I'm fine with this
solution as is.

I definitely agree we need tests for this.

jamie.
part-000.sig (application/pgp-signature)

Thread: