Hi all,

Alina Friedrichsen napsal(a):
Hi!

The correct syntax is [ -n "${var}" ] (notice the quotes).
Thanks to Vasilis.

A security notice:

It can become a security issue when any function is wrongly used in a security 
context.
I would mark this one only as a general warning.

Don't use more then one expression in one test call.

You can freely use test concatenated by logical operators if you know how the 
used shell handles them and prevent the wrong behavior by protecting variables. 
It is just not portable.

Use instant two test calls:

if [ -z "$x" ] && [ -z "$y" ]; then
    echo x and y are empty
fi

For example:
if [ "x$x" = x -a "x$y" = x ] ; then
or
if [[ -z "$x" && -z "$y" ]] ; then ## in bash
would do the same thing but either way is not portable (-a and [[).


if [ -z "$x" ] || [ -z "$y" ]; then
    echo x or y is empty
fi

If more then one expression is done with test the comparison is exploitable.
It's a design error of the UNIX shell and can't be fixed.

I would not dare to say the one "UNIX shell". There are many shells. And every 
one of them has its own issues or quirks or exceptions.
Busybox (the original complaint was targeted to it) claims its POSIX compliance 
and it should handle -z/-n tests properly but the result is the same like in 
bash. The good way to handle it safely is to use portable expressions.

Some of them are well documented differences, you can look to the Autoconf 
manual. It has had to handle them to become a really multiplatform tool.
See for example: 
http://www.gnu.org/software/autoconf/manual/html_node/Limitations-of-Builtins.html#index-g_t_0040command_007btest_007d-1431


Regards
Alina

Best regards,
Lubos

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to