From: Johannes Schindelin Date: Mon, 28 Jan 2008 11:59:50 GMT Subject: Re: [PATCH] Fix off by one error in prep_exclude. Message-ID: In-Reply-To: <1201480650-19716-1-git-send-email-shawn.bohrer@gmail.com> Hi, On Sun, 27 Jan 2008, Shawn Bohrer wrote: > 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 I'll try to remember even 6 months from now that this was the "git clean -n /" problem ;-) Ciao, Dscho