Re: [PATCH] Fix off by one error in prep_exclude.
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 28, 2008, 11:59 UTC
- Message-ID
- <alpine.LSU.1.00.0801281159150.23907@racer.site>
- In-Reply-To
- <1201480650-19716-1-git-send-email-shawn.bohrer@gmail.com>
Hi,
On Sun, 27 Jan 2008, Shawn Bohrer wrote:
Show 32 quoted lines
> In "struct exclude_stack", prep_exclude() and excluded(), the
> convention for a path is to express the length of directory part
> including the trailing slash (e.g. "foo" and "bar/baz" will get
> baselen=0 and baselen=4 respectively).
>
> The variable current and parameter baselen follow that
> convention in the codepath the following patch touches.
>
> else {
> cp = strchr(base + current + 1, '/');
> if (!cp)
> die("oops in prep_exclude");
> cp++;
> }
> stk->prev = dir->exclude_stack;
> stk->baselen = cp - base;
>
> is about coming up with the next value for current (which is
> taken from stk->baselen) to dig one more level.
>
> If base="foo/bar/boo" and current=4 (i.e. we are looking at
> "foo/"), the current code (base + current + 1) will begin scanning
> for the next slash at ar/boo skipping one letter ('b'). This
> patch starts the scanning at bar/boo/
>
> This only causes a problem when a path component has a length of
> zero which can happen when the user provides an absolute path to
> a file or directory in the root directory (i.e. "/", or "/foo"),
> or if the input is malformed and contains a double-slash such
> as "foo//boo".
>
> Signed-off-by: Shawn Bohrer <shawn.bohrer@gmail.com>I'll try to remember even 6 months from now that this was the "git clean -n /" problem ;-)
Ciao, Dscho