From: Junio C Hamano Date: Thu, 07 Mar 2013 21:48:18 GMT Subject: Re: [PATCH] setup.c: Fix prefix_pathspec from looping pass end of string Message-ID: <7vobeulw4d.fsf@alter.siamese.dyndns.org> In-Reply-To: <1362674163-24682-1-git-send-email-andrew.kw.w@gmail.com> Andrew Wong writes: > The previous code was assuming length ends at either `)` or `,`, and was > not handling the case where strcspn returns length due to end of string. > So specifying ":(top" as pathspec will cause the loop to go pass the end > of string. Thanks. The parser that goes past the end of the string may be a bug worth fixing, but is this patch sufficient to diagnose such an input as an error? > Signed-off-by: Andrew Wong > --- > setup.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/setup.c b/setup.c > index 1dee47e..f4c4e73 100644 > --- a/setup.c > +++ b/setup.c > @@ -207,9 +207,11 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char > *copyfrom && *copyfrom != ')'; > copyfrom = nextat) { > size_t len = strcspn(copyfrom, ",)"); > - if (copyfrom[len] == ')') > + if (copyfrom[len] == '\0') > nextat = copyfrom + len; > - else > + else if (copyfrom[len] == ')') > + nextat = copyfrom + len; > + else if (copyfrom[len] == ',') > nextat = copyfrom + len + 1; > if (!len) > continue;