From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8999D3858D39; Tue, 18 Jan 2022 14:21:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8999D3858D39 From: "calestyo at scientia dot org" To: glibc-bugs@sourceware.org Subject: [Bug glob/28792] New: possible wrong behaviour with patterns with double [ with no closing ] Date: Tue, 18 Jan 2022 14:21:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: glob X-Bugzilla-Version: 2.33 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: calestyo at scientia dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2022 14:21:25 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D28792 Bug ID: 28792 Summary: possible wrong behaviour with patterns with double [ with no closing ] Product: glibc Version: 2.33 Status: UNCONFIRMED Severity: normal Priority: P2 Component: glob Assignee: unassigned at sourceware dot org Reporter: calestyo at scientia dot org Target Milestone: --- Hey. Forwarding this from: https://lore.kernel.org/dash/YeZbt7nhvODBSL0I@gondor.apana.org.au/T/#mb9438= ab3009b9e38a2e22fdd22e99ddd74078b93 where it was suggested that this may be a bug in fnmatch(). Assuming a pattern of: [.*^\] my understanding was that this would actually mean: - the literal string [. followed by - the pattern notation special character * (i.e. any string) followed by - the literal string ^] Because ] is escaped, it's to be taken literally and in a pattern a [ without corresponding ] is to be taken literally as well. (see POSIX, https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#t= ag_18_13 ) That seems to work in dash (which according to its maintainer uses fnmatch() for the matching): $ case '[.^]' in ([.*^\]) echo match;; (*) echo no match;; esac match $ case '[.x^]' in ([.*^\]) echo match;; (*) echo no match;; esac match $ case '[.xx^]' in ([.*^\]) echo match;; (*) echo no match;; esac match However, adding another [ to the pattern: [.*^[\] which should be: - the literal string [. followed by - the pattern notation special character * (i.e. any string) followed by - the literal string ^[] No longer matches: $ case '[.^[]' in ([.*^[\]) echo match;; (*) echo no match;; esac no match $ case '[.x^[]' in ([.*^[\]) echo match;; (*) echo no match;; esac no match $ case '[.xx^[]' in ([.*^[\]) echo match;; (*) echo no match;; esac no match Whereas, AFAIU POSIX, it should. This works, btw. in bash (no idea whether that uses fnmatch() too), but nei= ther in busybox sh, nor klibc sh. Thanks, Chris. --=20 You are receiving this mail because: You are on the CC list for the bug.=