From 692663303f67371a2e4af4e3d353b042f754c036 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 15 Oct 2012 13:24:34 +0700 Subject: [PATCH] exclude: stricten a length check in EXC_FLAG_ENDSWITH case MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This block of code deals with the "basename" part only, which has the length of "pathlen - (basename - pathname)". Stricten the length check and remove "pathname" from the main expression to avoid confusion. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dir.c b/dir.c index 0015cc54f..b0ae417b3 100644 --- a/dir.c +++ b/dir.c @@ -534,8 +534,9 @@ int excluded_from_list(const char *pathname, if (!strcmp_icase(exclude, basename)) return to_exclude; } else if (x->flags & EXC_FLAG_ENDSWITH) { - if (x->patternlen - 1 <= pathlen && - !strcmp_icase(exclude + 1, pathname + pathlen - x->patternlen + 1)) + int len = pathlen - (basename - pathname); + if (x->patternlen - 1 <= len && + !strcmp_icase(exclude + 1, basename + len - x->patternlen + 1)) return to_exclude; } else { if (fnmatch_icase(exclude, basename, 0) == 0) -- 2.26.2