8000 wildmatch: avoid undefined behavior · git/git@81b26f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 81b26f8

Browse files
phillipwoodgitster
authored andcommitted
wildmatch: avoid undefined behavior
The code changed in this commit is designed to check if the pattern starts with "**/" or contains "/**/" (see 3a078de (wildmatch: fix "**" special case, 2013-01-01)). Unfortunately when the pattern begins with "**/" `prev_p = p - 2` is evaluated when `p` points to the second "*" and so the subtraction is undefined according to section 6.5.6 of the C standard because the result does not point within the same object as `p`. Fix this by avoiding the subtraction unless it is well defined. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1f2e05f commit 81b26f8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

wildmatch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
8383
continue;
8484
case '*':
8585
if (*++p == '*') {
86-
const uchar *prev_p = p - 2;
86+
const uchar *prev_p = p;
8787
while (*++p == '*') {}
8888
if (!(flags & WM_PATHNAME))
8989
/* without WM_PATHNAME, '*' == '**' */
9090
match_slash = 1;
91-
else if ((prev_p < pattern || *prev_p == '/') &&
91+
else if ((prev_p - pattern < 2 || *(prev_p - 2) == '/') &&
9292
(*p == '\0' || *p == '/' ||
9393
(p[0] == '\\' && p[1] == '/'))) {
9494
/*

0 commit comments

Comments
 (0)
0