[PATCH] Fix off by one error in prep_exclude.
- From
Shawn Bohrer <shawn.bohrer@gmail.com>
- Date
- Jan 28, 2008, 00:37 UTC
- Message-ID
- <1201480650-19716-1-git-send-email-shawn.bohrer@gmail.com>
- In-Reply-To
- <20080128003404.GA18276@lintop>
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> --- dir.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/dir.c b/dir.c index 3e345c2..9e5879a 100644 --- a/dir.c +++ b/dir.c @@ -237,7 +237,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen) current = 0; } else { - cp = strchr(base + current + 1, '/'); + cp = strchr(base + current, '/'); if (!cp) die("oops in prep_exclude"); cp++;
-- 1.5.4.rc5.1.g813e