From 2494611a68c0d85babb8f0cfac6c296b64b3ea45 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 8 Aug 2012 22:09:35 +2000 Subject: [PATCH] Re: [PATCH] sprinters: bugfix when NULL passed for a string. --- 76/2b73d6972aa00cffa6ecc8f57a8478defe576e | 165 ++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 76/2b73d6972aa00cffa6ecc8f57a8478defe576e diff --git a/76/2b73d6972aa00cffa6ecc8f57a8478defe576e b/76/2b73d6972aa00cffa6ecc8f57a8478defe576e new file mode 100644 index 000000000..4d1c7f50a --- /dev/null +++ b/76/2b73d6972aa00cffa6ecc8f57a8478defe576e @@ -0,0 +1,165 @@ +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 D1C2D431FAF + for ; Tue, 7 Aug 2012 19:09:38 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 zde-URIVCPyf for ; + Tue, 7 Aug 2012 19:09:38 -0700 (PDT) +Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU + [18.9.25.12]) + by olra.theworths.org (Postfix) with ESMTP id 14682431FAE + for ; Tue, 7 Aug 2012 19:09:38 -0700 (PDT) +X-AuditID: 1209190c-b7f806d000006b87-53-5021ca61b9da +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP + id 86.CB.27527.16AC1205; Tue, 7 Aug 2012 22:09:37 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q7829aLr010564; + Tue, 7 Aug 2012 22:09:37 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q7829ZOv024972 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Tue, 7 Aug 2012 22:09:36 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SyviJ-0004Gs-CK; Tue, 07 Aug 2012 22:09:35 -0400 +From: Austin Clements +To: Mark Walters , + Ben Gamari , notmuch@notmuchmail.org +Subject: Re: [PATCH] sprinters: bugfix when NULL passed for a string. +In-Reply-To: <874noe1o0r.fsf@qmul.ac.uk> +References: <871ujjuu2z.fsf@gmail.com> <878vdrp4d9.fsf@qmul.ac.uk> + <874noe1o0r.fsf@qmul.ac.uk> +User-Agent: Notmuch/0.13.2+131~g3e2f67b (http://notmuchmail.org) Emacs/23.3.1 + (i486-pc-linux-gnu) +Date: Tue, 07 Aug 2012 22:09:35 -0400 +Message-ID: <87ipcut9r4.fsf@awakening.csail.mit.edu> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFnrPIsWRmVeSWpSXmKPExsUixCmqrZt4SjHAYMYdJYvlq6QsVs/lsbh+ + cyazA7PHzll32T2erbrFHMAUxWWTkpqTWZZapG+XwJXRuSa/4KVkxaOW5awNjN0iXYycHBIC + JhItsxcxQthiEhfurWfrYuTiEBLYxygx8cZhVghnPaPEpsXrmCCcE0wSe/auh8osYZQ4vP8/ + C0g/m4CGxLb9y4FmcXCICBRLLG0yBQkLC7hK3NrzlRXE5gQq2fGqmR3EFhKIk/i/5CzYalGB + RIn7q/6A1bAIqErs3vKRGcTmBTrv9aUDrBC2oMTJmU/AVjELaEnc+PeSaQKjwCwkqVlIUgsY + mVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpGurlZpbopaaUbmIEh6Ukzw7GNweVDjEKcDAq8fBG + JysGCLEmlhVX5h5ilORgUhLlnX0SKMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmEd89BoBxvSmJl + VWpRPkxKmoNFSZz3cspNfyGB9MSS1OzU1ILUIpisDAeHkgTvM5ChgkWp6akVaZk5JQhpJg5O + kOE8QMMfg9TwFhck5hZnpkPkTzHqctx//uQ2oxBLXn5eqpQ4712QIgGQoozSPLg5sHTyilEc + 6C1h3k6QKh5gKoKb9ApoCRPQEm95OZAlJYkIKakGRpfKI8sMrHojrD8rs9kuEDNlSbh1fFam + YJVJodeu3yxsz5iy1546s20a86YlP8ODl3qvnb7T3pnl4dXvfx1aFEXEruucU3KKXX//rVe+ + jMadKkfpeWV151jWm3u/OJ7pcMHk+zmT7UtDlgW7OSSYJz+fFq+5fVOn57zwfoYDZ8WYJjDt + eLanW4mlOCPRUIu5qDgRAMSWr8ICAwAA +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: Wed, 08 Aug 2012 02:09:39 -0000 + +LGTM. + +This won't commute with [0], since that introduces broken tests that are +fixed by this patch. + +I think we should remove the fields in the JSON header object for +missing headers (except perhaps From and Date, if those really are +mandatory headers), but I think we should do that after the freeze, +since it might affect frontends. It probably makes sense to add an +Emacs test or two to the tests in [0]. + +[0] id:"1344389313-7886-1-git-send-email-amdragon@mit.edu" + +On Tue, 07 Aug 2012, Mark Walters wrote: +> 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 +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2