From: Phillip Wood <phillip.wood123@gmail.com>
To: git@vger.kernel.org
Cc: Derrick Stolee <derrickstolee@github.com>,
Jeff King <peff@peff.net>,
Phillip Wood <phillip.wood123@gmail.com>,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: [PATCH 2/3] wildmatch: avoid undefined behavior
Date: Mon, 20 Mar 2023 16:10:01 +0000 [thread overview]
Message-ID: <c6f2d44622f10cfee3c48a7d13b3de9607d1061d.1679328580.git.phillip.wood@dunelm.org.uk> (raw)
In-Reply-To: <cover.1679328580.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>
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>
---
wildmatch.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/wildmatch.c b/wildmatch.c
index 06861bd8bc..694d2f8e40 100644
--- a/wildmatch.c
+++ b/wildmatch.c
@@ -83,12 +83,12 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
continue;
case '*':
if (*++p == '*') {
- const uchar *prev_p = p - 2;
+ const uchar *prev_p = p;
while (*++p == '*') {}
if (!(flags & WM_PATHNAME))
/* without WM_PATHNAME, '*' == '**' */
match_slash = 1;
- else if ((prev_p < pattern || *prev_p == '/') &&
+ else if ((prev_p - pattern < 2 || *(prev_p - 2) == '/') &&
(*p == '\0' || *p == '/' ||
(p[0] == '\\' && p[1] == '/'))) {
/*
--
2.39.2
next prev parent reply other threads:[~2023-03-20 16:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-20 16:09 [PATCH 0/3] wildmatch: fix exponential behavior Phillip Wood
2023-03-20 16:10 ` [PATCH 1/3] " Phillip Wood
2023-03-24 22:17 ` [PATCH] t3070: make chain lint tester happy Michael J Gruber
2023-03-25 6:37 ` Jeff King
2023-03-25 6:54 ` Eric Sunshine
2023-03-25 7:58 ` Jeff King
2023-03-25 8:04 ` Jeff King
2023-03-25 8:18 ` Eric Sunshine
2023-03-25 8:41 ` Jeff King
2023-03-25 8:51 ` Jeff King
2023-03-25 9:09 ` Eric Sunshine
2023-03-25 19:47 ` Jeff King
2023-03-25 9:17 ` Eric Sunshine
2023-03-26 14:30 ` Phillip Wood
2023-03-26 14:54 ` Michael J Gruber
2023-03-25 8:06 ` Eric Sunshine
2023-03-25 8:36 ` Jeff King
2023-03-20 16:10 ` Phillip Wood [this message]
2023-03-20 16:10 ` [PATCH 3/3] wildmatch: hide internal return values Phillip Wood
2023-03-20 17:58 ` [PATCH 0/3] wildmatch: fix exponential behavior Junio C Hamano
2023-03-23 14:19 ` Derrick Stolee
2023-03-24 14:04 ` Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c6f2d44622f10cfee3c48a7d13b3de9607d1061d.1679328580.git.phillip.wood@dunelm.org.uk \
--to=phillip.wood123@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).