Weird behavior of 'ash' with "remove prefix/suffix pattern" in parameter expansion

Denys Vlasenko vda.linux at googlemail.com
Thu Nov 24 09:55:07 UTC 2016


On Thu, Nov 24, 2016 at 10:29 AM, Denys Vlasenko
<vda.linux at googlemail.com> wrote:
>>> busybox 1.25.0
>>> $ TEST="[ \t\r]"
>>> $ echo ${TEST%]}
>>> [ \t\r
>>> $ echo ${TEST#[}
>>> [ \t\r]
>>>
>>> GNU bash, version 3.2.39
>>> $ TEST="[ \t\r]"
>>> echo ${TEST%]}
>>> [ \t\r
>>> echo "${TEST#[}"
>>>  \t\r]
>>>
>>> It seems that ${#} does not eat [:
>>> TEST="[[[[" ; echo "${TEST#[}"
>>> [[[[
>>> TEST="[[[[" ; echo "${TEST#[}"
>>> [[[
>>
>> Reproduced. Looks like a bug in uclibc:
>>
>> pmatch("[","[") returns 0 "no match",
>>
>> but in glibc, it returns 1.
>
> Just for the record. "pmatch" I talked about is
> a define in ash.c, on libc level, it's fnmatch:
>
> #define pmatch(a, b) !fnmatch((a), (b), 0)

glibc fixed this in 2011:

commit 794c3ad3a405697e2663b00f616e319383b9bb7d
Author: Ulrich Drepper <drepper at gmail.com>
Date:   Fri Jan 14 08:06:22 2011 -0500

    FIx handling of unterminated [ expression in fnmatch.



Here's a patch for uclibc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fnmatch.patch
Type: text/x-patch
Size: 862 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20161124/9ca3fb58/attachment.bin>


More information about the busybox mailing list