Re: [PATCH v3 09/12] sparse-checkout: properly match escaped characters
- From
Jeff King <peff@peff.net>
- Date
- Jan 29, 2020, 10:03 UTC
- Message-ID
- <20200129100309.GA4218@coredump.intra.peff.net>
- In-Reply-To
- <9ea69e90694e53842acd68d3ac85c9a00c4bd343.1580236003.git.gitgitgadget@gmail.com>
On Tue, Jan 28, 2020 at 06:26:40PM +0000, Derrick Stolee via GitGitGadget wrote:
Show 5 quoted lines
> From: Derrick Stolee <dstolee@microsoft.com> > > 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]"?
Show 25 quoted lines
> +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