From: Junio C Hamano Date: Tue, 15 Jan 2013 19:29:16 GMT Subject: Re: [PATCH] attr: fix off-by-one directory component length calculation Message-ID: <7vwqve2qk3.fsf@alter.siamese.dyndns.org> In-Reply-To: <201301152014.28433.avila.jn@gmail.com> "Jean-Noël AVILA" writes: > Thank you for the explanation. > > I did not monitor the system calls when writing that patch. > Where is the perf framework? > > As the mistake is located in the "find_basename" function, I would propose a > fix directly into it so that the output fits what the other functions expect. Isn't that a crazy semantics for the function, though? I would expect find_basename("/a/path/to/file") to return "file", not "/file". > > Something in the line of: > > diff --git a/attr.c b/attr.c > index d6d7190..b6e72f3 100644 > --- a/attr.c > +++ b/attr.c > @@ -572,7 +572,7 @@ static const char *find_basename(const char *path) > if (*cp == '/' && cp[1]) > last_slash = cp; > } > - return last_slash ? last_slash + 1 : path; > + return last_slash ? last_slash : path; > } > > static void prepare_attr_stack(const char *path) > @@ -770,6 +770,10 @@ static void collect_all_attrs(const char *path) > check_all_attr[i].value = ATTR__UNKNOWN; > > basename = find_basename(path); > + /* the slash is included in the basename > + so that it can be matched by a directory pattern */ > + if (basename != path) > + basename++; > pathlen = strlen(path); > rem = attr_nr; > for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)