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 412034196F4 for ; Tue, 6 Apr 2010 01:17:46 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[BAYES_40=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001] autolearn=ham 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 VQU35p0RkO+t for ; Tue, 6 Apr 2010 01:17:45 -0700 (PDT) Received: from mail-gy0-f181.google.com (mail-gy0-f181.google.com [209.85.160.181]) by olra.theworths.org (Postfix) with ESMTP id 720624196F0 for ; Tue, 6 Apr 2010 01:17:45 -0700 (PDT) Received: by gyg8 with SMTP id 8so2575952gyg.26 for ; Tue, 06 Apr 2010 01:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:received:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=3FVGXrclAGAnpw3LKZdskcykb3kM88DoLZCssAe5OMk=; b=jORJdZGsLov5yydErhTCRl1Mdi2xD/qnquf1IPqbnffCBExwbw0t8zp9qSoG2JsnKy XZcQVN+m7xfhiuDC289FHslq9B2oL8lgmXtqQTL2xfzJtIQLu48EqB2h5eodf5CpKykp 5UjboIVrtWb4aWy57I4sw2OWjwTRmKqHFN1+k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=cWrH6GQNIqcF1OuqlliWtkaTOYti1pwcB532p1bY7H5wpGUkpq04ZT/erCITvBnEuM xi/ss0/UZzMsEHXDOQjHHDM6a9vd01LjpkNryr9NxUci1YG5ylkJqDfOaI5iK6d+P8Yn v7nqKhdyCxOMxH+HTJOofwBQDNL2KGroUxDh4= MIME-Version: 1.0 Sender: anthony.j.towns@gmail.com Received: by 10.90.114.1 with HTTP; Tue, 6 Apr 2010 01:17:44 -0700 (PDT) In-Reply-To: <877holavq5.fsf@ut.hh.sledj.net> References: <877holavq5.fsf@ut.hh.sledj.net> Date: Tue, 6 Apr 2010 18:17:44 +1000 X-Google-Sender-Auth: d62a4c2bd810c785 Received: by 10.91.154.4 with SMTP id g4mr1172925ago.26.1270541864873; Tue, 06 Apr 2010 01:17:44 -0700 (PDT) Message-ID: Subject: Re: [PATCH] json: Avoid calling strlen(NULL) From: Anthony Towns To: David Edmondson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: notmuch 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, 06 Apr 2010 08:17:46 -0000 On Tue, Apr 6, 2010 at 17:25, David Edmondson wrote: > =A0 =A0json: Avoid calling strlen(NULL) > =A0 =A0MIME parts may have no filename, which previously resulted in call= ing > =A0 =A0strlen(NULL). > =A0char * > =A0json_quote_str(const void *ctx, const char *str) > =A0{ > + =A0 =A0if (str =3D=3D NULL) > + =A0 =A0 =A0 return (char *)"\"\""; > + > =A0 =A0 return (json_quote_chararray (ctx, str, strlen (str))); > =A0} There's already a check in json_quote_chararray for len=3D=3D0, so it might be sensible to say: return (json_quote_chararray (ctx, str, str !=3D NULL ? strlen (str) : = 0)); OTOH, the code in json_quote_array to deal with that does the same thing (returns a literal string containing two quote marks), which seems wrong -- the normal code path is to talloc to get a newly allocated, editable string, that might be talloc_free'd later, wouldn't it make more sense just to let the str=3D=3DNULL / len=3D=3D0 behaviour fall through into the normal case code? FWIW: commit 5b93a488221b50c02db18d86a550cb3c038c00da Author: Anthony Date: Tue Apr 6 18:10:39 2010 +1000 json: Avoid calling strlen(NULL), and always return a newly talloced ar= ray. MIME parts may have a no filename, which causes json_quote_str() to be invoked with NULL instead of a string. diff --git a/json.c b/json.c index f90b0fa..5e379ef 100644 --- a/json.c +++ b/json.c @@ -57,9 +57,6 @@ json_quote_chararray(const void *ctx, const char *str, const size_t len) size_t loop; size_t required; - if (len =3D=3D 0) - return (char *)"\"\""; - for (loop =3D 0, required =3D 0, ptr =3D str; loop < len; loop++, required++, ptr++) { @@ -105,5 +102,8 @@ json_quote_chararray(const void *ctx, const char *str, const size_t len) char * json_quote_str(const void *ctx, const char *str) { + if (str =3D=3D NULL) + str =3D ""; + return (json_quote_chararray (ctx, str, strlen (str))); } --=20 Anthony Towns