[klibc] possible wrong behaviour with patterns with [ with no closing ]

Christoph Anton Mitterer calestyo at scientia.org
Sun Jan 16 19:35:06 PST 2022


Hey.


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 already seems to fail in klibc sh:
$ 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 it works in bash, dash and busybox sh.)




I've stumbled over this, when looking for another possible bug in dash
and busybox sh:


When, 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 ^[]

Also doesn't match in klibc sh:
$ 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 case with more than one [ works, btw. in bash, but neither in
busybox sh, nor klibc sh.


Cheers,
Chris.


More information about the klibc mailing list