From patchwork Tue Aug 4 07:50:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11699871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61566913 for ; Tue, 4 Aug 2020 07:50:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 86C7A2067C for ; Tue, 4 Aug 2020 07:50:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729409AbgHDHuT (ORCPT ); Tue, 4 Aug 2020 03:50:19 -0400 Received: from cloud.peff.net ([104.130.231.41]:47386 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbgHDHuT (ORCPT ); Tue, 4 Aug 2020 03:50:19 -0400 Received: (qmail 614 invoked by uid 109); 4 Aug 2020 07:50:18 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Tue, 04 Aug 2020 07:50:18 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 9744 invoked by uid 111); 4 Aug 2020 07:50:18 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Tue, 04 Aug 2020 03:50:18 -0400 Authentication-Results: peff.net; auth=none Date: Tue, 4 Aug 2020 03:50:17 -0400 From: Jeff King To: git@vger.kernel.org Cc: Taylor Blau Subject: [PATCH 3/3] revision: avoid leak when preparing bloom filter for "/" Message-ID: <20200804075017.GC284046@coredump.intra.peff.net> References: <20200804074146.GA190027@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200804074146.GA190027@coredump.intra.peff.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org If we're given an empty pathspec, we refuse to set up bloom filters, as described in f3c2a36810 (revision: empty pathspecs should not use Bloom filters, 2020-07-01). But before the empty string check, we drop any trailing slash by allocating a new string without it. So a pathspec consisting only of "/" will allocate that string, but then still cause us to bail, leaking the new string. Let's make sure to free it. Signed-off-by: Jeff King --- Just noticed while reading the function to fix the previous patch. I'm not even sure if it's possible to get here with a pathspec of "/", since we'd probably give a "/ is outside repository" error before then. So maybe this case doesn't even matter. If it doesn't, then it might simplify the function a bit to do the empty-pathspec check before handling trailing slashes. But handling it does help make it more clear this function is doing the right thing no matter what input it is given, so that's what I went with here. revision.c | 1 + 1 file changed, 1 insertion(+) diff --git a/revision.c b/revision.c index 5ed86e4524..b80868556b 100644 --- a/revision.c +++ b/revision.c @@ -702,6 +702,7 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs) len = strlen(path); if (!len) { revs->bloom_filter_settings = NULL; + free(path_alloc); return; }