exclude: stricten a length check in EXC_FLAG_ENDSWITH case
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 15 Oct 2012 06:24:34 +0000 (13:24 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Oct 2012 21:57:16 +0000 (14:57 -0700)
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c

diff --git a/dir.c b/dir.c
index 0015cc54f455cf48e6e2d66c23ecebfa017fcf00..b0ae417b37278ab9c60c8c69764e6837bc12d7d4 100644 (file)
--- 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)