Re: [PATCH] sprinters: bugfix when NULL passed for a string.
authorAustin Clements <amdragon@MIT.EDU>
Wed, 8 Aug 2012 02:09:35 +0000 (22:09 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:58 +0000 (09:48 -0800)
76/2b73d6972aa00cffa6ecc8f57a8478defe576e [new file with mode: 0644]

diff --git a/76/2b73d6972aa00cffa6ecc8f57a8478defe576e b/76/2b73d6972aa00cffa6ecc8f57a8478defe576e
new file mode 100644 (file)
index 0000000..4d1c7f5
--- /dev/null
@@ -0,0 +1,165 @@
+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 D1C2D431FAF\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Aug 2012 19:09:38 -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 zde-URIVCPyf for <notmuch@notmuchmail.org>;\r
+       Tue,  7 Aug 2012 19:09:38 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
+       [18.9.25.12])\r
+       by olra.theworths.org (Postfix) with ESMTP id 14682431FAE\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Aug 2012 19:09:38 -0700 (PDT)\r
+X-AuditID: 1209190c-b7f806d000006b87-53-5021ca61b9da\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 86.CB.27527.16AC1205; Tue,  7 Aug 2012 22:09:37 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q7829aLr010564; \r
+       Tue, 7 Aug 2012 22:09:37 -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 q7829ZOv024972\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 7 Aug 2012 22:09:36 -0400 (EDT)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SyviJ-0004Gs-CK; Tue, 07 Aug 2012 22:09:35 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>,\r
+       Ben Gamari <bgamari.foss@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] sprinters: bugfix when NULL passed for a string.\r
+In-Reply-To: <874noe1o0r.fsf@qmul.ac.uk>\r
+References: <871ujjuu2z.fsf@gmail.com> <878vdrp4d9.fsf@qmul.ac.uk>\r
+       <874noe1o0r.fsf@qmul.ac.uk>\r
+User-Agent: Notmuch/0.13.2+131~g3e2f67b (http://notmuchmail.org) Emacs/23.3.1\r
+       (i486-pc-linux-gnu)\r
+Date: Tue, 07 Aug 2012 22:09:35 -0400\r
+Message-ID: <87ipcut9r4.fsf@awakening.csail.mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFnrPIsWRmVeSWpSXmKPExsUixCmqrZt4SjHAYMYdJYvlq6QsVs/lsbh+\r
+       cyazA7PHzll32T2erbrFHMAUxWWTkpqTWZZapG+XwJXRuSa/4KVkxaOW5awNjN0iXYycHBIC\r
+       JhItsxcxQthiEhfurWfrYuTiEBLYxygx8cZhVghnPaPEpsXrmCCcE0wSe/auh8osYZQ4vP8/\r
+       C0g/m4CGxLb9y4FmcXCICBRLLG0yBQkLC7hK3NrzlRXE5gQq2fGqmR3EFhKIk/i/5CzYalGB\r
+       RIn7q/6A1bAIqErs3vKRGcTmBTrv9aUDrBC2oMTJmU/AVjELaEnc+PeSaQKjwCwkqVlIUgsY\r
+       mVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpGurlZpbopaaUbmIEh6Ukzw7GNweVDjEKcDAq8fBG\r
+       JysGCLEmlhVX5h5ilORgUhLlnX0SKMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmEd89BoBxvSmJl\r
+       VWpRPkxKmoNFSZz3cspNfyGB9MSS1OzU1ILUIpisDAeHkgTvM5ChgkWp6akVaZk5JQhpJg5O\r
+       kOE8QMMfg9TwFhck5hZnpkPkTzHqctx//uQ2oxBLXn5eqpQ4712QIgGQoozSPLg5sHTyilEc\r
+       6C1h3k6QKh5gKoKb9ApoCRPQEm95OZAlJYkIKakGRpfKI8sMrHojrD8rs9kuEDNlSbh1fFam\r
+       YJVJodeu3yxsz5iy1546s20a86YlP8ODl3qvnb7T3pnl4dXvfx1aFEXEruucU3KKXX//rVe+\r
+       jMadKkfpeWV151jWm3u/OJ7pcMHk+zmT7UtDlgW7OSSYJz+fFq+5fVOn57zwfoYDZ8WYJjDt\r
+       eLanW4mlOCPRUIu5qDgRAMSWr8ICAwAA\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: Wed, 08 Aug 2012 02:09:39 -0000\r
+\r
+LGTM.\r
+\r
+This won't commute with [0], since that introduces broken tests that are\r
+fixed by this patch.\r
+\r
+I think we should remove the fields in the JSON header object for\r
+missing headers (except perhaps From and Date, if those really are\r
+mandatory headers), but I think we should do that after the freeze,\r
+since it might affect frontends.  It probably makes sense to add an\r
+Emacs test or two to the tests in [0].\r
+\r
+[0] id:"1344389313-7886-1-git-send-email-amdragon@mit.edu"\r
+\r
+On Tue, 07 Aug 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> The string function in a sprinter may be called with a NULL string\r
+> pointer (eg if a header is absent). This causes a segfault. We fix\r
+> this by checking for a null pointer in the string functions and update\r
+> the sprinter documentation.\r
+>\r
+> At the moment some output when format=text is done directly rather than\r
+> via an sprinter: in that case a null pointer is passed to printf or\r
+> similar and a "(null)" appears in the output. That behaviour is not\r
+> changed in this patch.\r
+> ---\r
+>\r
+> This could really do with some tests (it is the second time this type of\r
+> bug has occurred). To be considered as a message by notmuch new a file\r
+> needs at least one of a From: Subject: or To: header. Thus we should\r
+> have three messages each of which just contains that single header (and\r
+> nothing else) and check that search and show work as expected. \r
+>\r
+>\r
+>\r
+>  sprinter-json.c |    2 ++\r
+>  sprinter-text.c |    2 ++\r
+>  sprinter.h      |    4 +++-\r
+>  3 files changed, 7 insertions(+), 1 deletions(-)\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
+> diff --git a/sprinter-text.c b/sprinter-text.c\r
+> index dfa54b5..10343be 100644\r
+> --- a/sprinter-text.c\r
+> +++ b/sprinter-text.c\r
+> @@ -38,6 +38,8 @@ text_string_len (struct sprinter *sp, const char *val, size_t len)\r
+>  static void\r
+>  text_string (struct sprinter *sp, const char *val)\r
+>  {\r
+> +    if (val == NULL)\r
+> +    val = "";\r
+>      text_string_len (sp, val, strlen (val));\r
+>  }\r
+>  \r
+> diff --git a/sprinter.h b/sprinter.h\r
+> index 5f43175..912a526 100644\r
+> --- a/sprinter.h\r
+> +++ b/sprinter.h\r
+> @@ -27,7 +27,9 @@ typedef struct sprinter {\r
+>       * a list or map, followed or preceded by separators).  For string\r
+>       * and string_len, the char * must be UTF-8 encoded.  string_len\r
+>       * allows non-terminated strings and strings with embedded NULs\r
+> -     * (though the handling of the latter is format-dependent).\r
+> +     * (though the handling of the latter is format-dependent). For\r
+> +     * string (but not string_len) the string pointer passed may be\r
+> +     * NULL.\r
+>       */\r
+>      void (*string) (struct sprinter *, const char *);\r
+>      void (*string_len) (struct sprinter *, const char *, size_t);\r
+> -- \r
+> 1.7.9.1\r
+>\r
+>\r
+> H\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r