From 6c19fb9008e2dcd7a2d4ce42f618ec2079b1230f Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 23 Jun 2022 16:05:17 +0100 Subject: win32: bug fix in fnmatch(3) A user reports: Here is the shell script that causes me problems: var=foo:bar echo ${var#*[[:space:]]} What expect I to see echoed is foo:bar, however what I see bar. It seems that the [[:space:]] character class is matching the colon character in addition to whitespace characters. I see the same problem with the [[:blank:]] character class. This is due to a bug in the WIN32 implementation of fnmatch(3) which is derived from an old snapshot of glibc code (glibc commit 7814856974 from 1999-09-12). The bug was fixed in glibc by commit 83b1b6d8fa of 2000-07-04. Apply the equivalent fix to our version. --- win32/fnmatch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/win32/fnmatch.c b/win32/fnmatch.c index 7d8fde6a2..77b54c5f5 100644 --- a/win32/fnmatch.c +++ b/win32/fnmatch.c @@ -423,6 +423,7 @@ internal_fnmatch (const char *pattern, const char *string, goto matched; break; } + c = *p++; # endif } else if (c == '\0') @@ -463,13 +464,14 @@ internal_fnmatch (const char *pattern, const char *string, matched: /* Skip the rest of the [...] that already matched. */ - while (c != ']') + do { + c = *p++; + if (c == '\0') /* [... (unterminated) loses. */ return FNM_NOMATCH; - c = *p++; if (!(flags & FNM_NOESCAPE) && c == '\\') { if (*p == '\0') @@ -487,6 +489,7 @@ internal_fnmatch (const char *pattern, const char *string, c = *p; } } + while (c != ']'); if (not) return FNM_NOMATCH; } -- cgit v1.2.3-55-g6feb