From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: libc-alpha@sourceware.org
Cc: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Subject: [PATCH 2/2] posix: correctly detect invalid classes after match in fnmatch()
Date: Tue, 23 May 2023 00:37:32 -0700 [thread overview]
Message-ID: <20230523073732.6956-3-carenas@gmail.com> (raw)
In-Reply-To: <20230523073732.6956-1-carenas@gmail.com>
Always validate class names when parsing a [:class:] expression
* posix/fnmatch_loop.c (internal_fnmatch/internal_fnwmatch)
remove comment about an specification bug that is no longer relevant
adjust inequality to include 'z' as a valid character in class names
replace soft failure with a hard one when invalid names are used
---
posix/fnmatch_loop.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c
index 4be2e20141..a6b5c69a95 100644
--- a/posix/fnmatch_loop.c
+++ b/posix/fnmatch_loop.c
@@ -866,29 +866,30 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
{
if (*p == L_('\0'))
return FNM_NOMATCH;
- /* XXX 1003.2d11 is unclear if this is right. */
+
++p;
}
else if (c == L_('[') && *p == L_(':'))
{
- int c1 = 0;
- const CHAR *startp = p;
+ CHAR str[CHAR_CLASS_MAX_LENGTH + 1];
+ size_t c1 = 0;
while (1)
{
c = *++p;
- if (++c1 == CHAR_CLASS_MAX_LENGTH)
- return FNM_NOMATCH;
-
- if (*p == L_(':') && p[1] == L_(']'))
+ if (c == L_(':') && p[1] == L_(']'))
break;
- if (c < L_('a') || c >= L_('z'))
- {
- p = startp - 2;
- break;
- }
+ if (c1 == CHAR_CLASS_MAX_LENGTH ||
+ (c < L_('a') || c > L_('z')))
+ return FNM_NOMATCH;
+
+ str[c1++] = c;
}
+ str[c1] = L_('\0');
+ if (IS_CHAR_CLASS (str) == 0)
+ return FNM_NOMATCH;
+
p += 2;
}
else if (c == L_('[') && *p == L_('='))
--
2.39.2
prev parent reply other threads:[~2023-05-23 7:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 7:37 [PATCH 0/2] posix: fix fnmatch() inconsistency BZ#30483 Carlo Marcelo Arenas Belón
2023-05-23 7:37 ` [PATCH 1/2] fnmatch: allow character class names with 'z' Carlo Marcelo Arenas Belón
2023-05-23 18:09 ` Adhemerval Zanella Netto
2023-05-23 21:55 ` Carlo Arenas
2023-05-26 14:25 ` Adhemerval Zanella Netto
2023-05-23 7:37 ` Carlo Marcelo Arenas Belón [this message]
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=20230523073732.6956-3-carenas@gmail.com \
--to=carenas@gmail.com \
--cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).