Re: [PATCH v4 10/16] Add n_d_add_message_with_indexopts (extension of n_d_add_message)
[notmuch-archives.git] / 57 / 86535014a79f4b58fe08d348c53cfe811f8d15
1 Return-Path: <m.walters@qmul.ac.uk>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 70F49431FC0\r
6         for <notmuch@notmuchmail.org>; Tue,  7 Aug 2012 12:49:05 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id XceZp9xB5JdH for <notmuch@notmuchmail.org>;\r
17         Tue,  7 Aug 2012 12:49:03 -0700 (PDT)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 2D421431FAF\r
22         for <notmuch@notmuchmail.org>; Tue,  7 Aug 2012 12:49:03 -0700 (PDT)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1Syplz-0003By-89; Tue, 07 Aug 2012 20:48:59 +0100\r
27 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
28         helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1Syply-0000gY-Vb; Tue, 07 Aug 2012 20:48:59 +0100\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: Ben Gamari <bgamari.foss@gmail.com>, notmuch@notmuchmail.org\r
34 Subject: [PATCH] sprinters: bugfix when NULL passed for a string.\r
35 In-Reply-To: <878vdrp4d9.fsf@qmul.ac.uk>\r
36 References: <871ujjuu2z.fsf@gmail.com> <878vdrp4d9.fsf@qmul.ac.uk>\r
37 User-Agent: Notmuch/0.13.2+96~g634443c (http://notmuchmail.org) Emacs/23.4.1\r
38         (x86_64-pc-linux-gnu)\r
39 Date: Tue, 07 Aug 2012 20:48:52 +0100\r
40 Message-ID: <874noe1o0r.fsf@qmul.ac.uk>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain; charset=us-ascii\r
43 X-Sender-Host-Address: 94.192.233.223\r
44 X-QM-SPAM-Info: Sender has good ham record.  :)\r
45 X-QM-Body-MD5: f6ef7ad763fd7bbb21b5eb2ab71bcae5 (of first 20000 bytes)\r
46 X-SpamAssassin-Score: -1.8\r
47 X-SpamAssassin-SpamBar: -\r
48 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
49         determine if it is\r
50         spam. We require at least 5.0 points to mark a message as spam.\r
51         This message scored -1.8 points.\r
52         Summary of the scoring: \r
53         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
54         *      medium trust\r
55         *      [138.37.6.40 listed in list.dnswl.org]\r
56         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
57         provider *      (markwalters1009[at]gmail.com)\r
58         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
59         *      domain\r
60         *  0.5 AWL AWL: From: address is in the auto white-list\r
61 X-QM-Scan-Virus: ClamAV says the message is clean\r
62 X-BeenThere: notmuch@notmuchmail.org\r
63 X-Mailman-Version: 2.1.13\r
64 Precedence: list\r
65 List-Id: "Use and development of the notmuch mail system."\r
66         <notmuch.notmuchmail.org>\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
70 List-Post: <mailto:notmuch@notmuchmail.org>\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
73         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
74 X-List-Received-Date: Tue, 07 Aug 2012 19:49:05 -0000\r
75 \r
76 \r
77 The string function in a sprinter may be called with a NULL string\r
78 pointer (eg if a header is absent). This causes a segfault. We fix\r
79 this by checking for a null pointer in the string functions and update\r
80 the sprinter documentation.\r
81 \r
82 At the moment some output when format=text is done directly rather than\r
83 via an sprinter: in that case a null pointer is passed to printf or\r
84 similar and a "(null)" appears in the output. That behaviour is not\r
85 changed in this patch.\r
86 ---\r
87 \r
88 This could really do with some tests (it is the second time this type of\r
89 bug has occurred). To be considered as a message by notmuch new a file\r
90 needs at least one of a From: Subject: or To: header. Thus we should\r
91 have three messages each of which just contains that single header (and\r
92 nothing else) and check that search and show work as expected. \r
93 \r
94 \r
95 \r
96  sprinter-json.c |    2 ++\r
97  sprinter-text.c |    2 ++\r
98  sprinter.h      |    4 +++-\r
99  3 files changed, 7 insertions(+), 1 deletions(-)\r
100 \r
101 diff --git a/sprinter-json.c b/sprinter-json.c\r
102 index c9b6835..0a07790 100644\r
103 --- a/sprinter-json.c\r
104 +++ b/sprinter-json.c\r
105 @@ -118,6 +118,8 @@ json_string_len (struct sprinter *sp, const char *val, size_t len)\r
106  static void\r
107  json_string (struct sprinter *sp, const char *val)\r
108  {\r
109 +    if (val == NULL)\r
110 +       val = "";\r
111      json_string_len (sp, val, strlen (val));\r
112  }\r
113  \r
114 diff --git a/sprinter-text.c b/sprinter-text.c\r
115 index dfa54b5..10343be 100644\r
116 --- a/sprinter-text.c\r
117 +++ b/sprinter-text.c\r
118 @@ -38,6 +38,8 @@ text_string_len (struct sprinter *sp, const char *val, size_t len)\r
119  static void\r
120  text_string (struct sprinter *sp, const char *val)\r
121  {\r
122 +    if (val == NULL)\r
123 +       val = "";\r
124      text_string_len (sp, val, strlen (val));\r
125  }\r
126  \r
127 diff --git a/sprinter.h b/sprinter.h\r
128 index 5f43175..912a526 100644\r
129 --- a/sprinter.h\r
130 +++ b/sprinter.h\r
131 @@ -27,7 +27,9 @@ typedef struct sprinter {\r
132       * a list or map, followed or preceded by separators).  For string\r
133       * and string_len, the char * must be UTF-8 encoded.  string_len\r
134       * allows non-terminated strings and strings with embedded NULs\r
135 -     * (though the handling of the latter is format-dependent).\r
136 +     * (though the handling of the latter is format-dependent). For\r
137 +     * string (but not string_len) the string pointer passed may be\r
138 +     * NULL.\r
139       */\r
140      void (*string) (struct sprinter *, const char *);\r
141      void (*string_len) (struct sprinter *, const char *, size_t);\r
142 -- \r
143 1.7.9.1\r
144 \r
145 \r
146 H\r