about summary refs log tree commit diff
path: root/posix/fnmatch_loop.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@linux-m68k.org>2022-01-18 16:31:39 +0100
committerAndreas Schwab <schwab@linux-m68k.org>2022-01-24 17:13:33 +0100
commit8442f0d966da5a9333e961af9e98b41aabdd9f1b (patch)
treea2d119ef37abe3e91b5e53822e52e289419d4711 /posix/fnmatch_loop.c
parent84d2d0fe20bdf94feed82b21b4d7d136db471f03 (diff)
downloadglibc-8442f0d966da5a9333e961af9e98b41aabdd9f1b.tar.gz
glibc-8442f0d966da5a9333e961af9e98b41aabdd9f1b.tar.xz
glibc-8442f0d966da5a9333e961af9e98b41aabdd9f1b.zip
Fix handling of unterminated bracket expressions in fnmatch (bug 28792)
When fnmatch processes a bracket expression, and eventually finds it to be
unterminated, it should rescan it, treating the starting bracket as a
normal character.  That didn't happen when a matching character was found
while scanning the bracket expression.
Diffstat (limited to 'posix/fnmatch_loop.c')
-rw-r--r--posix/fnmatch_loop.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c
index cab4e1b684..9445ed9c58 100644
--- a/posix/fnmatch_loop.c
+++ b/posix/fnmatch_loop.c
@@ -823,8 +823,13 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
             while ((c = *p++) != L_(']'))
               {
                 if (c == L_('\0'))
-                  /* [... (unterminated) loses.  */
-                  return FNM_NOMATCH;
+		  {
+		    /* [ unterminated, treat as normal character.  */
+		    p = p_init;
+		    n = n_init;
+		    c = L_('[');
+		    goto normal_match;
+		  }
 
                 if (!(flags & FNM_NOESCAPE) && c == L_('\\'))
                   {