From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 2D2021F4B4 for ; Wed, 20 Jan 2021 23:41:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729654AbhATW3V (ORCPT ); Wed, 20 Jan 2021 17:29:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731143AbhATVvl (ORCPT ); Wed, 20 Jan 2021 16:51:41 -0500 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FBB6C0613CF for ; Wed, 20 Jan 2021 13:50:34 -0800 (PST) Received: by mail-qv1-xf2a.google.com with SMTP id s6so11668153qvn.6 for ; Wed, 20 Jan 2021 13:50:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gitlab.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3rma9WePIZOSZjctww7z7QG2fIyRV4pamXU0bsLXQE4=; b=N8dZrn9xRhOwYLbwcQlUBYjZKjiSvnVrzeVjllksWn9ESHZV2kV8hxZtV36bsKyde7 tLS1o4Mf5Gta+lSrYXF8HaL+cSMlSg8nmbw9j9GszGLw5tKNfvCIor+PGcMDWK5wiQDI 7fruXGxKH52hPrXUKMuU5vZfcsqDsiFLmLQlU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3rma9WePIZOSZjctww7z7QG2fIyRV4pamXU0bsLXQE4=; b=MS18Yy1qYgH61A4yxQ/MKp8jEupi3uP40h8rtz5+F+pOiLy1ZhLWcadYb5GjWnE5p7 PUvmJF7bVE/Q4DhCj4H/LGIBIELXniIbAC3jeMP5B3qN7PdjF9945oOzjDIyQhJ6NQpZ ahZnpLIWM8pyAaVGJ4yQqPV486XGqIdtT/MP+b4CzsYRrngtPWVeAL4buC+6tDKJT1Jo B0HSD91dDfAzlnsvk9tS9ygx7/oszja9hfr0tWojM2bZD7iN8Z8GXmf6iDYn1lP6zJ0t Fh+b0MEdQM68JnuJAVNR9zByzMJ3xcuFQ6ExbmR3CSXkNr/8oLk2l3xiwqKtressDesw hJkg== X-Gm-Message-State: AOAM531ieuR0eQXDhvk65WWiWXLl4YVBZulrytlE6ju2sCjBGxPCKu55 0vNSf2qId34RyuPznVzc7VZ60hAJKfhRKadLyijHfcKky/gFpg== X-Google-Smtp-Source: ABdhPJwJNuiShQsNtOMZFZUDLjotLdVWR8rofdQLf3bjKxpllL7nmMRk9AMCRoRvS6y0T4miX57JODqJrQ0jQ18U6gc= X-Received: by 2002:a0c:b59a:: with SMTP id g26mr11480950qve.26.1611179433574; Wed, 20 Jan 2021 13:50:33 -0800 (PST) MIME-Version: 1.0 References: <5fc081b2d554db305400ec52fac8683a3ed59597.1611158549.git.me@ttaylorr.com> In-Reply-To: <5fc081b2d554db305400ec52fac8683a3ed59597.1611158549.git.me@ttaylorr.com> From: Jacob Vosmaer Date: Wed, 20 Jan 2021 22:50:22 +0100 Message-ID: Subject: Re: [PATCH v2 2/3] ls-refs.c: initialize 'prefixes' before using it To: Taylor Blau Cc: Git Mailing List , Jeff King Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As the person whose name is on the "From:" line, I approve. And thanks! On Wed, Jan 20, 2021 at 5:04 PM Taylor Blau wrote: > > From: Jacob Vosmaer > > Correctly initialize the "prefixes" strvec using strvec_init() instead > of simply zeroing it via the earlier memset(). > > There's no way to trigger a crash, since the first 'ref-prefix' command > will initialize the strvec via the 'ALLOC_GROW' in 'strvec_push_nodup()' > (the alloc and nr variables are already zero'd, so the call to > ALLOC_GROW is valid). > > If no "ref-prefix" command was given, then the call to > 'ls-refs.c:ref_match()' will abort early after it reads the zero in > 'prefixes->nr'. Likewise, strvec_clear() will only call free() on the > array, which is NULL, so we're safe there, too. > > But, all of this is dangerous and requires more reasoning than it would > if we simply called 'strvec_init()', so do that. > > Signed-off-by: Jacob Vosmaer > Signed-off-by: Taylor Blau > --- > ls-refs.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/ls-refs.c b/ls-refs.c > index a1e0b473e4..367597d447 100644 > --- a/ls-refs.c > +++ b/ls-refs.c > @@ -90,6 +90,7 @@ int ls_refs(struct repository *r, struct strvec *keys, > struct ls_refs_data data; > > memset(&data, 0, sizeof(data)); > + strvec_init(&data.prefixes); > > git_config(ls_refs_config, NULL); > > -- > 2.30.0.138.g6d7191ea01 >