From: Zurab Kvachadze <zurabid2016@gmail.com>
To: dash@vger.kernel.org
Cc: Zurab Kvachadze <zurabid2016@gmail.com>
Subject: [PATCH 2/2] expand: pmatch(): Fix buffer overread caused by passing array of chars as string
Date: Tue, 29 Apr 2025 23:47:32 +0200 [thread overview]
Message-ID: <20250429214732.22390-3-zurabid2016@gmail.com> (raw)
In-Reply-To: <20250429214732.22390-1-zurabid2016@gmail.com>
strpbrk() accepts two null-terminated string arguments. stop[] is char
array that is not null-terminated but is still passed as a second
argument to strpbrk. This causes buffer overread, which is detected by
AddressSanitizer.
This commit adds an explicit null-terminated to the end of the array.
Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
---
src/expand.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/expand.c b/src/expand.c
index 171c135..8cff60d 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1890,7 +1890,9 @@ static __attribute__((noinline)) int ccmatch(char *p, const char *mbc, int ml,
static int pmatch(char *pattern, const char *string)
{
- char stop[] = { 0, CTLESC, CTLMBCHAR };
+ /* stop should be null-terminated as it passed as a string to
+ * strpbrk. */
+ char stop[] = { 0, CTLESC, CTLMBCHAR, '\0' };
const char *q;
unsigned mb;
char *p;
--
2.45.3
next prev parent reply other threads:[~2025-04-29 21:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 21:47 [PATCH 0/2] Fix two buffer overflows Zurab Kvachadze
2025-04-29 21:47 ` [PATCH 1/2] expand: Fix negative size parameter to memmove in subevalvar() Zurab Kvachadze
2025-05-02 5:34 ` Herbert Xu
2025-05-02 5:45 ` Herbert Xu
2025-04-29 21:47 ` Zurab Kvachadze [this message]
2025-05-03 7:23 ` [PATCH 2/2] expand: pmatch(): Fix buffer overread caused by passing array of chars as string Herbert Xu
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250429214732.22390-3-zurabid2016@gmail.com \
--to=zurabid2016@gmail.com \
--cc=dash@vger.kernel.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox