From 30be875ca5f47705e6bdaa745905aeb8853e5060 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 8 Aug 2012 08:49:15 +2000 Subject: [PATCH] Re: Segmentation fault in notmuch search --format=json --- ba/a0c92c23960ddd0ceb54e3fd51d3cc14ed9766 | 126 ++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 ba/a0c92c23960ddd0ceb54e3fd51d3cc14ed9766 diff --git a/ba/a0c92c23960ddd0ceb54e3fd51d3cc14ed9766 b/ba/a0c92c23960ddd0ceb54e3fd51d3cc14ed9766 new file mode 100644 index 000000000..ef574c674 --- /dev/null +++ b/ba/a0c92c23960ddd0ceb54e3fd51d3cc14ed9766 @@ -0,0 +1,126 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 0C593431FC4 + for ; Tue, 7 Aug 2012 05:49:24 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 1flQOIelNzX8 for ; + Tue, 7 Aug 2012 05:49:20 -0700 (PDT) +Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU + [18.7.68.35]) + by olra.theworths.org (Postfix) with ESMTP id 2487C431FAF + for ; Tue, 7 Aug 2012 05:49:20 -0700 (PDT) +X-AuditID: 12074423-b7f396d0000008f4-ad-50210ecd9fc5 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP + id D8.5D.02292.DCE01205; Tue, 7 Aug 2012 08:49:18 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q77CnH6X018421; + Tue, 7 Aug 2012 08:49:17 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q77CnFZI003356 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Tue, 7 Aug 2012 08:49:16 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SyjDn-0006EP-Pm; Tue, 07 Aug 2012 08:49:15 -0400 +Date: Tue, 7 Aug 2012 08:49:15 -0400 +From: Austin Clements +To: Mark Walters +Subject: Re: Segmentation fault in notmuch search --format=json +Message-ID: <20120807124857.GN22601@mit.edu> +References: <871ujjuu2z.fsf@gmail.com> + <878vdrp4d9.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <878vdrp4d9.fsf@qmul.ac.uk> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmpnleLIzCtJLcpLzFFi42IRYrdT1z3HpxhgsOYLs8XyVVIWq+fyWFy/ + OZPZgdlj56y77B7PVt1iDmCK4rJJSc3JLEst0rdL4MqY/fIIY8FTvop53XPZGhibubsYOTkk + BEwkFsx7ywJhi0lcuLeerYuRi0NIYB+jxPzOpSwQznpGiWPvf0M5J5gkPr3YzwzhLGGU2Lu8 + hRWkn0VAReLg5jVMIDabgIbEtv3LGUFsEQEdiduHFrCD2MwCDhLXb5xnBrGFBewlltycCtbL + C1Tz+sYSNhBbSMBFon/XXTaIuKDEyZlPWCB6tSRu/HsJNJ8DyJaWWP6PAyTMCbTqyIVHYGNE + gU6YcnIb2wRGoVlIumch6Z6F0L2AkXkVo2xKbpVubmJmTnFqsm5xcmJeXmqRrplebmaJXmpK + 6SZGcHi7KO9g/HNQ6RCjAAejEg/vBS6FACHWxLLiytxDjJIcTEqivMq8igFCfEn5KZUZicUZ + 8UWlOanFhxglOJiVRHgP7wQq501JrKxKLcqHSUlzsCiJ815LuekvJJCeWJKanZpakFoEk5Xh + 4FCS4J0PMlSwKDU9tSItM6cEIc3EwQkynAdouAIwHQjxFhck5hZnpkPkTzEqSonzSoMkBEAS + GaV5cL2w9POKURzoFWHevyAreICpC677FdBgJqDB3vJyIINLEhFSUg2MDPPbP0kUFs86y7BL + 4e+6nfvTF3fae/g5VkW8EPuy+KtjR/aepTxqs7/fEY58XFpT/Cx2Ydekw4sX2e7uto6c8HvW + xm05T49wZd5pWzB7k33b2QNqFbNWPQ6/mJlj1j394LJiwRuTGU7za039s9F53rGUxnVv7wZI + XalhMo0x2+MXeSSA87AgqxJLcUaioRZzUXEiAOnjdDsaAwAA +Cc: notmuch@notmuchmail.org +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 07 Aug 2012 12:49:24 -0000 + +Quoth Mark Walters on Aug 07 at 8:07 am: +> On Tue, 07 Aug 2012, Ben Gamari 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 +> 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. + +LGTM. We'll want to do something similar for text_string and, of +course, update the sprinter doc comments. + +> 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)); +> } +> -- 2.26.2