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

YourFritz - framework framework at yourfritz.de
Tue Nov 22 16:18:31 UTC 2016


Hi,

I've found the following strange result while testing.

Running the command

    busybox sh -x -c 'test="[ \t\r]";[ ${#test} -gt 0 ] && \
( [ "${test#[}" = "$test" ] || [ "${test%]}" = "$test" ] ) && \
echo true || echo false'

produces the unexpected output

    + test=[ \t\r]
    + [ 7 -gt 0 ]
    + [ [ \t\r] = [ \t\r] ]
    + echo true
    true

- the first square bracket wasn't removed by "${test#[}", the
following comparison finds no difference and the whole (inner) term
evaluates to "true". The "remove suffix pattern" shows the same effect.

This busybox version has been built with uClibc-0.9.33.2 for MIPS
(34kc). Two different builds show the same behavior, one version came
from a router vendor (AVM) in Germany and the other was made by myself.

    AVM => BusyBox v1.22.1 (2016-11-01 19:55:42 CET) multi-call binary.
    own => BusyBox v1.24.2 (2016-09-24 17:17:47 CEST) multi-call binary.

Running the same command on x86 with a glibc-based BusyBox leads to the
expected result:

    + test=[ \t\r]
    + [ 7 -gt 0 ]
    + [  \t\r] = [ \t\r] ]
    + [ [ \t\r = [ \t\r] ]
    + echo false
    false

I haven't looked into the sources yet, probably it's a misbehavior of
the underlying C library?

Have I overlooked something important here?

If it's really a problem (one case has to be wrong in my opinion *g*)
and the proposal to fix it, is expected beside this pure notification, I
would try to track down the issue.
-- 
Best regards / mfG

.PeH

framework at yourfritz.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x30311D96.asc
Type: application/pgp-keys
Size: 7373 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20161122/76a34276/attachment-0001.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20161122/76a34276/attachment-0001.asc>


More information about the busybox mailing list