From: Mark Walters Date: Tue, 7 Aug 2012 07:07:14 +0000 (+0100) Subject: Re: Segmentation fault in notmuch search --format=json X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=edaafdd5999617bccc6076dd0da69c37ea251d5b;p=notmuch-archives.git Re: Segmentation fault in notmuch search --format=json --- diff --git a/ad/3882e69ec5ece5d63fa5da5079761205638bea b/ad/3882e69ec5ece5d63fa5da5079761205638bea new file mode 100644 index 000000000..56552d221 --- /dev/null +++ b/ad/3882e69ec5ece5d63fa5da5079761205638bea @@ -0,0 +1,122 @@ +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 28AB2431FC0 + for ; Tue, 7 Aug 2012 00:07:28 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 IxGIHB1npRPQ for ; + Tue, 7 Aug 2012 00:07:27 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 4B077431FAF + for ; Tue, 7 Aug 2012 00:07:27 -0700 (PDT) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1Sydsv-0004Wx-5r; Tue, 07 Aug 2012 08:07:23 +0100 +Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] + helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1Sydsu-0004hu-QX; Tue, 07 Aug 2012 08:07:21 +0100 +From: Mark Walters +To: Ben Gamari , notmuch@notmuchmail.org +Subject: Re: Segmentation fault in notmuch search --format=json +In-Reply-To: <871ujjuu2z.fsf@gmail.com> +References: <871ujjuu2z.fsf@gmail.com> +User-Agent: Notmuch/0.13.2+96~g634443c (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Tue, 07 Aug 2012 08:07:14 +0100 +Message-ID: <878vdrp4d9.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 94.192.233.223 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: cb4bcd839c256c4625019fd72fc50e77 (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay + * domain + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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 07:07:28 -0000 + +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. + + +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)); + } + +