]> git.ipfire.org Git - thirdparty/git.git/commit - wildmatch.c
wildmatch: avoid undefined behavior
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Mon, 20 Mar 2023 16:10:01 +0000 (16:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Mar 2023 17:58:53 +0000 (10:58 -0700)
commit81b26f8f2891f1a63d5dbf7c2d4209b8325062b6
tree15ea9d31fbc9dec051f835546ceb48f7ae5efb18
parent1f2e05f0b794d9e4b1cf07d63c9efd1325893ecc
wildmatch: avoid undefined behavior

The code changed in this commit is designed to check if the pattern
starts with "**/" or contains "/**/" (see 3a078dec33 (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>
wildmatch.c