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 59CB2431FD7 for ; Tue, 12 Nov 2013 13:32:43 -0800 (PST) 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 lgZYRcSfHlTL for ; Tue, 12 Nov 2013 13:32:31 -0800 (PST) Received: from mail-bk0-f48.google.com (mail-bk0-f48.google.com [209.85.214.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D5D93431FCF for ; Tue, 12 Nov 2013 13:32:30 -0800 (PST) Received: by mail-bk0-f48.google.com with SMTP id u15so832061bkz.7 for ; Tue, 12 Nov 2013 13:32:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-type; bh=M/YbBzezTzw00UXgIqqaAuPxmaN09QDUyL4xikGrmOE=; b=Pz1AFkdRcEdec5ZVorv2D4iQueoR80Hdq+B0pupLRSDP+I8l5VR0XCncH5JAa5mxi5 h+AV++s8l0YG0tvZkG3B7dc8h/C5mAoVzN9sUFxmAkGp677e/AjPDUfl5MTpvMuF4fVA sCEyPuHZKU8s/nBO0T+ZmfvtmpKQHpGgvqdJFGThEIXIiRnYgSEQggsKIB2XwIENDGEm trMTWglRE7BlshAgQD9qm3jIqn88oJQPLCHdfekOWjxD0CzawnfQ9rpMb9pIqllV87fj NPy37pN2CL2/vF1zGDkNuFVOfY0LSKwo9l9M09M1dFDHFvmloOCUop4kupb0Z9YrjPzF gCow== X-Gm-Message-State: ALoCoQk0UWZVIDt/qVN621Dz8DgGrZsWoU8qq7HomXDVrTIYQqt6VLAW1pu2J/eGQnbYUaHocWrA X-Received: by 10.204.200.78 with SMTP id ev14mr3228617bkb.32.1384291949523; Tue, 12 Nov 2013 13:32:29 -0800 (PST) Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. [88.195.111.91]) by mx.google.com with ESMTPSA id w9sm19898744bkn.12.2013.11.12.13.32.27 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 12 Nov 2013 13:32:28 -0800 (PST) From: Jani Nikula To: Peter Zijlstra , Austin Clements Subject: Re: [PATCH] notmuch: Add "maildir:" search option In-Reply-To: <20131112194727.GE16796@laptop.programming.kicks-ass.net> References: <20131112155637.GA16796@laptop.programming.kicks-ass.net> <87mwl94dte.fsf@awakening.csail.mit.edu> <20131112194727.GE16796@laptop.programming.kicks-ass.net> User-Agent: Notmuch/0.16+145~gebbaa94 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Tue, 12 Nov 2013 23:32:23 +0200 Message-ID: <87ob5pi9w8.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain 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: Tue, 12 Nov 2013 21:32:43 -0000 On Tue, 12 Nov 2013, Peter Zijlstra wrote: > On Tue, Nov 12, 2013 at 02:31:25PM -0500, Austin Clements wrote: >> > + /* Strip the maildir "cur", "new" directory entries. */ >> > + i = strlen(maildir); >> > + if (strncmp(maildir + i - 3, "cur", 3) == 0 || >> > + strncmp(maildir + i - 3, "new", 3) == 0) { >> >> This is unsafe if directory is less than three characters, which I >> believe could happen if the message is in the root mail directory (which >> shouldn't happen with a well-formed maildir, but notmuch doesn't require >> maildir, and, regardless, we should be defensive). >> >> Also, we have a STRNCMP_LITERAL macro that we often use for comparisons >> with string literals, but I'm good with this, too. > > Quite so, I haven't actually seen that, but you're quite right. FWIW, in this particular case you can just strcmp because you are looking at the end of maildir. BR, Jani.