On Thu, Nov 24, 2016 at 10:29 AM, Denys Vlasenko
<[email protected]> 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 <[email protected]>
Date: Fri Jan 14 08:06:22 2011 -0500
FIx handling of unterminated [ expression in fnmatch.
Here's a patch for uclibc
diff --git a/libc/misc/fnmatch/fnmatch_loop.c b/libc/misc/fnmatch/fnmatch_loop.c
index 6d037f8..a09cfbb 100644
--- a/libc/misc/fnmatch/fnmatch_loop.c
+++ b/libc/misc/fnmatch/fnmatch_loop.c
@@ -204,6 +204,8 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
case L('['):
{
/* Nonzero if the sense of the character class is inverted. */
+ CHAR *p_init = p;
+ CHAR *n_init = n;
register int not;
CHAR cold;
UCHAR fn;
@@ -409,8 +411,13 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
}
#endif
else if (c == L('\0'))
- /* [ (unterminated) loses. */
- return FNM_NOMATCH;
+ {
+ /* [ unterminated, treat as normal character. */
+ p = p_init;
+ n = n_init;
+ c = L('[');
+ goto normal_match;
+ }
else
{
int is_range = 0;
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox