From 26b97c456e6bde140ab3f03e4480b31bcbb1c59b Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 9 Aug 2012 17:28:48 +2000 Subject: [PATCH] Re: [PATCH] sprinters: bugfix when NULL passed for a string. --- a4/12e927216ac3b2be2e767bdebb57789b616eb4 | 169 ++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 a4/12e927216ac3b2be2e767bdebb57789b616eb4 diff --git a/a4/12e927216ac3b2be2e767bdebb57789b616eb4 b/a4/12e927216ac3b2be2e767bdebb57789b616eb4 new file mode 100644 index 000000000..f2b408918 --- /dev/null +++ b/a4/12e927216ac3b2be2e767bdebb57789b616eb4 @@ -0,0 +1,169 @@ +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 1CA35431FAF + for ; Wed, 8 Aug 2012 14:28:52 -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 erSxp7q8C250 for ; + Wed, 8 Aug 2012 14:28:51 -0700 (PDT) +Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU + [18.7.68.37]) + by olra.theworths.org (Postfix) with ESMTP id 54A10431FAE + for ; Wed, 8 Aug 2012 14:28:51 -0700 (PDT) +X-AuditID: 12074425-b7f9b6d0000008c4-23-5022da12613e +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP + id 5F.5D.02244.21AD2205; Wed, 8 Aug 2012 17:28:50 -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 q78LSoQ3018316; + Wed, 8 Aug 2012 17:28:50 -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 q78LSmJ1017281 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Wed, 8 Aug 2012 17:28:49 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SzDo8-0007I1-Ok; Wed, 08 Aug 2012 17:28:48 -0400 +Date: Wed, 8 Aug 2012 17:28:48 -0400 +From: Austin Clements +To: Mark Walters +Subject: Re: [PATCH] sprinters: bugfix when NULL passed for a string. +Message-ID: <20120808212848.GF11179@mit.edu> +References: <1344374501-28185-1-git-send-email-amdragon@mit.edu> + <1344389313-7886-1-git-send-email-amdragon@mit.edu> + <87mx25ulgq.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <87mx25ulgq.fsf@qmul.ac.uk> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFupnleLIzCtJLcpLzFFi42IR4hTV1hW6pRRgsOKLnsXquTwW12/OZHZg + 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4MnZfO8NSMFWy4uCDPcwNjNuEuxg5OSQETCSW + Na1lhbDFJC7cW8/WxcjFISSwj1Fiw+QrzBDOekaJjQvOs0A4J5gkFnzoYodwljBK7L94mx2k + n0VARWLn6wlsIDabgIbEtv3LGUFsEQEdiduHFoDVMAtIS3z73cwEYgsLuErc2vMVbDcvUM2s + 9+sZIYZOYZTofDKPDSIhKHFy5hMWiGYtiRv/XgI1c4ANWv6PA8TkBNp1oNkIpEIU6IQpJ7ex + TWAUmoWkeRaS5lkIzQsYmVcxyqbkVunmJmbmFKcm6xYnJ+blpRbpWujlZpbopaaUbmIEhTW7 + i+oOxgmHlA4xCnAwKvHwam1QChBiTSwrrsw9xCjJwaQkyrvoIlCILyk/pTIjsTgjvqg0J7X4 + EKMEB7OSCG/1NqAcb0piZVVqUT5MSpqDRUmc90bKTX8hgfTEktTs1NSC1CKYrAwHh5IEr+5N + oEbBotT01Iq0zJwShDQTByfIcB6g4fYgNbzFBYm5xZnpEPlTjLoc958/uc0oxJKXn5cqJc6r + A1IkAFKUUZoHNweWjl4xigO9JcwbBFLFA0xlcJNeAS1hAlpyWBRsSUkiQkqqgfGC883egz/+ + GUma8bS0blz17XSHp0NYMEtcMP/HgoXFhotf6jxNTlhTFNP6/bwXC+cSRV/Dslm/v/AG1de9 + utBSfsC54afcmgY2b8kDDzfpCrlwGE17/7aseeoPmzkHNi1+t1vl1SUOv2/qB2+tOD/5m4WS + lVC12k2TrU2Gu5M8MyrUpIWfcCuxFGckGmoxFxUnAgDf6r5dIgMAAA== +Cc: notmuch@notmuchmail.org +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 21:28:52 -0000 + +LGTM! + +Quoth Mark Walters on Aug 08 at 10:23 pm: +> +> 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 is the same as id:"874noe1o0r.fsf@qmul.ac.uk" except for being +> based on top of the test in the parent message, and marking the broken +> test fixed. +> +> Best wishes +> +> Mark +> +> sprinter-json.c | 2 ++ +> sprinter-text.c | 2 ++ +> sprinter.h | 4 +++- +> test/missing-headers | 2 -- +> 4 files changed, 7 insertions(+), 3 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); +> diff --git a/test/missing-headers b/test/missing-headers +> index e79f922..f14b878 100755 +> --- a/test/missing-headers +> +++ b/test/missing-headers +> @@ -29,7 +29,6 @@ thread:XXX 2001-01-05 [1/1] (null); (inbox unread) +> thread:XXX 1970-01-01 [1/1] Notmuch Test Suite; (inbox unread)" +> +> test_begin_subtest "Search: json" +> -test_subtest_known_broken +> output=$(notmuch search --format=json '*' | notmuch_search_sanitize) +> test_expect_equal_json "$output" ' +> [ +> @@ -93,7 +92,6 @@ Body +> +message}" +> +> test_begin_subtest "Show: json" +> -test_subtest_known_broken +> output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize) +> test_expect_equal_json "$output" ' +> [ -- 2.26.2