From: Mark Walters Date: Tue, 7 Aug 2012 19:48:52 +0000 (+0100) Subject: [PATCH] sprinters: bugfix when NULL passed for a string. X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=371adee985ac8f8f32cacadcb290fb30d882b528;p=notmuch-archives.git [PATCH] sprinters: bugfix when NULL passed for a string. --- diff --git a/57/86535014a79f4b58fe08d348c53cfe811f8d15 b/57/86535014a79f4b58fe08d348c53cfe811f8d15 new file mode 100644 index 000000000..fdae4fe55 --- /dev/null +++ b/57/86535014a79f4b58fe08d348c53cfe811f8d15 @@ -0,0 +1,146 @@ +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 70F49431FC0 + for ; Tue, 7 Aug 2012 12:49:05 -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 XceZp9xB5JdH for ; + Tue, 7 Aug 2012 12:49:03 -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 2D421431FAF + for ; Tue, 7 Aug 2012 12:49:03 -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 1Syplz-0003By-89; Tue, 07 Aug 2012 20:48:59 +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 1Syply-0000gY-Vb; Tue, 07 Aug 2012 20:48:59 +0100 +From: Mark Walters +To: Ben Gamari , notmuch@notmuchmail.org +Subject: [PATCH] sprinters: bugfix when NULL passed for a string. +In-Reply-To: <878vdrp4d9.fsf@qmul.ac.uk> +References: <871ujjuu2z.fsf@gmail.com> <878vdrp4d9.fsf@qmul.ac.uk> +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 20:48:52 +0100 +Message-ID: <874noe1o0r.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: f6ef7ad763fd7bbb21b5eb2ab71bcae5 (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 19:49:05 -0000 + + +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