Bug 28792 - possible wrong behaviour with patterns with double [ with no closing ]
Summary: possible wrong behaviour with patterns with double [ with no closing ]
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: glob (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: 2.35
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-18 14:21 UTC by Christoph Anton Mitterer
Modified: 2022-01-24 16:28 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Anton Mitterer 2022-01-18 14:21:25 UTC
Hey.

Forwarding this from:

https://lore.kernel.org/dash/YeZbt7nhvODBSL0I@gondor.apana.org.au/T/#mb9438ab3009b9e38a2e22fdd22e99ddd74078b93

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#tag_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 neither in busybox sh, nor klibc sh.


Thanks,
Chris.
Comment 1 Andreas Schwab 2022-01-24 16:17:17 UTC
Fixed in 2.35.
Comment 2 Christoph Anton Mitterer 2022-01-24 16:28:08 UTC
Thanks :-)