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-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 433211F466 for ; Wed, 29 Jan 2020 10:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726186AbgA2KDL (ORCPT ); Wed, 29 Jan 2020 05:03:11 -0500 Received: from cloud.peff.net ([104.130.231.41]:47324 "HELO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726067AbgA2KDK (ORCPT ); Wed, 29 Jan 2020 05:03:10 -0500 Received: (qmail 16019 invoked by uid 109); 29 Jan 2020 10:03:10 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with SMTP; Wed, 29 Jan 2020 10:03:10 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 15402 invoked by uid 111); 29 Jan 2020 10:10:46 -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; Wed, 29 Jan 2020 05:10:46 -0500 Authentication-Results: peff.net; auth=none Date: Wed, 29 Jan 2020 05:03:09 -0500 From: Jeff King To: Derrick Stolee via GitGitGadget Cc: git@vger.kernel.org, me@ttaylorr.com, newren@gmail.com, Derrick Stolee Subject: Re: [PATCH v3 09/12] sparse-checkout: properly match escaped characters Message-ID: <20200129100309.GA4218@coredump.intra.peff.net> References: <9ea69e90694e53842acd68d3ac85c9a00c4bd343.1580236003.git.gitgitgadget@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <9ea69e90694e53842acd68d3ac85c9a00c4bd343.1580236003.git.gitgitgadget@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Tue, Jan 28, 2020 at 06:26:40PM +0000, Derrick Stolee via GitGitGadget wrote: > From: Derrick Stolee > > In cone mode, the sparse-checkout feature uses hashset containment > queries to match paths. Make this algorithm respect escaped asterisk > (*) and backslash (\) characters. Do we also need to worry about other glob metacharacters? E.g., "?" or ranges like "[A-Z]"? > +static char *dup_and_filter_pattern(const char *pattern) > +{ > + char *set, *read; > + char *result = xstrdup(pattern); > + > + set = result; > + read = result; > + > + while (*read) { > + /* skip escape characters (once) */ > + if (*read == '\\') > + read++; > + > + *set = *read; > + > + set++; > + read++; > + } > + *set = 0; > + > + if (*(read - 2) == '/' && *(read - 1) == '*') > + *(read - 2) = 0; > + > + return result; > +} Do we need to check that the pattern is longer than 1 character here? If it's a single character, it seems like this "*(read - 2)" will dereference the byte before the string. -Peff