Re: Segmentation fault in notmuch search --format=json
authorAustin Clements <amdragon@MIT.EDU>
Tue, 7 Aug 2012 12:49:15 +0000 (08:49 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:55 +0000 (09:48 -0800)
ba/a0c92c23960ddd0ceb54e3fd51d3cc14ed9766 [new file with mode: 0644]

diff --git a/ba/a0c92c23960ddd0ceb54e3fd51d3cc14ed9766 b/ba/a0c92c23960ddd0ceb54e3fd51d3cc14ed9766
new file mode 100644 (file)
index 0000000..ef574c6
--- /dev/null
@@ -0,0 +1,126 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0C593431FC4\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Aug 2012 05:49:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 1flQOIelNzX8 for <notmuch@notmuchmail.org>;\r
+       Tue,  7 Aug 2012 05:49:20 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id 2487C431FAF\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Aug 2012 05:49:20 -0700 (PDT)\r
+X-AuditID: 12074423-b7f396d0000008f4-ad-50210ecd9fc5\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id D8.5D.02292.DCE01205; Tue,  7 Aug 2012 08:49:18 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q77CnH6X018421; \r
+       Tue, 7 Aug 2012 08:49:17 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q77CnFZI003356\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 7 Aug 2012 08:49:16 -0400 (EDT)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SyjDn-0006EP-Pm; Tue, 07 Aug 2012 08:49:15 -0400\r
+Date: Tue, 7 Aug 2012 08:49:15 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: Segmentation fault in notmuch search --format=json\r
+Message-ID: <20120807124857.GN22601@mit.edu>\r
+References: <871ujjuu2z.fsf@gmail.com>\r
+ <878vdrp4d9.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <878vdrp4d9.fsf@qmul.ac.uk>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmpnleLIzCtJLcpLzFFi42IRYrdT1z3HpxhgsOYLs8XyVVIWq+fyWFy/\r
+       OZPZgdlj56y77B7PVt1iDmCK4rJJSc3JLEst0rdL4MqY/fIIY8FTvop53XPZGhibubsYOTkk\r
+       BEwkFsx7ywJhi0lcuLeerYuRi0NIYB+jxPzOpSwQznpGiWPvf0M5J5gkPr3YzwzhLGGU2Lu8\r
+       hRWkn0VAReLg5jVMIDabgIbEtv3LGUFsEQEdiduHFrCD2MwCDhLXb5xnBrGFBewlltycCtbL\r
+       C1Tz+sYSNhBbSMBFon/XXTaIuKDEyZlPWCB6tSRu/HsJNJ8DyJaWWP6PAyTMCbTqyIVHYGNE\r
+       gU6YcnIb2wRGoVlIumch6Z6F0L2AkXkVo2xKbpVubmJmTnFqsm5xcmJeXmqRrplebmaJXmpK\r
+       6SZGcHi7KO9g/HNQ6RCjAAejEg/vBS6FACHWxLLiytxDjJIcTEqivMq8igFCfEn5KZUZicUZ\r
+       8UWlOanFhxglOJiVRHgP7wQq501JrKxKLcqHSUlzsCiJ815LuekvJJCeWJKanZpakFoEk5Xh\r
+       4FCS4J0PMlSwKDU9tSItM6cEIc3EwQkynAdouAIwHQjxFhck5hZnpkPkTzEqSonzSoMkBEAS\r
+       GaV5cL2w9POKURzoFWHevyAreICpC677FdBgJqDB3vJyIINLEhFSUg2MDPPbP0kUFs86y7BL\r
+       4e+6nfvTF3fae/g5VkW8EPuy+KtjR/aepTxqs7/fEY58XFpT/Cx2Ydekw4sX2e7uto6c8HvW\r
+       xm05T49wZd5pWzB7k33b2QNqFbNWPQ6/mJlj1j394LJiwRuTGU7za039s9F53rGUxnVv7wZI\r
+       XalhMo0x2+MXeSSA87AgqxJLcUaioRZzUXEiAOnjdDsaAwAA\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 07 Aug 2012 12:49:24 -0000\r
+\r
+Quoth Mark Walters on Aug 07 at  8:07 am:\r
+> On Tue, 07 Aug 2012, Ben Gamari <bgamari.foss@gmail.com> wrote:\r
+> > It seems some messages trigger a segmentation fault in\r
+> > `do_search_threads()`. It appears the problem occurs (at least) when\r
+> > `authors` is NULL.\r
+> \r
+> Hi thanks for the bug report and detailed debugging. I think I can see\r
+> the problem and there is a test patch to fix it below, and this does\r
+> appear to be a regression.\r
+> \r
+> In json.c the function json_quote_str explicitly checks/allows for a\r
+> NULL pointer passed as a string and pretends it is just an empty\r
+> string. That behaviour was lost in the move to structured formatters.\r
+> \r
+> A simple fix is to put this check for a null pointer in json_string in\r
+> sprinter-json.c which is what this patch does.\r
+> \r
+> Incidentally this is the second time this bug has appeared: \r
+> \r
+>         commit cacefbf3d6dd5bce0b60b3cdfce29bfa371dfaea\r
+>         Author: David Edmondson <dme@dme.org>\r
+>         Date:   Tue Apr 6 08:24:00 2010 +0100\r
+> \r
+>             json: Avoid calling strlen(NULL)\r
+>                 \r
+>                     MIME parts may have no filename, which previously resulted in calling\r
+>                         strlen(NULL).\r
+> \r
+> so it really might be worth having a test for it!\r
+> \r
+> Finally, I think nothing in json.c is used anymore so perhaps it\r
+>  could be removed.\r
+\r
+LGTM.  We'll want to do something similar for text_string and, of\r
+course, update the sprinter doc comments.\r
+\r
+> diff --git a/sprinter-json.c b/sprinter-json.c\r
+> index c9b6835..0a07790 100644\r
+> --- a/sprinter-json.c\r
+> +++ b/sprinter-json.c\r
+> @@ -118,6 +118,8 @@ json_string_len (struct sprinter *sp, const char *val, size_t len)\r
+>  static void\r
+>  json_string (struct sprinter *sp, const char *val)\r
+>  {\r
+> +    if (val == NULL)\r
+> +    val = "";\r
+>      json_string_len (sp, val, strlen (val));\r
+>  }\r
+>  \r