Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

[[...]] is non-portable and has an extremely quirky corner case with variable expansion in arithmetic contexts, what's not to love?




I'm intrigued - any info on that?

I personally use ((...)) for arithmetic tests and [[...]] for all other tests as I just target new versions of BASH and don't care much about POSIX compatibility.


This is completely safe: [ "${payload}" -eq 42 ]

This can evaluate arbitrary code: [[ "${payload}" -eq 42 ]]

Here is one example of a malicious payload:

  payload='a[$(touch /tmp/pwned)]'

Thanks.

Now I need to figure out whether (( payload == 42 )) is safe.


It appears not.

It also does wildcards though, with POSIX you'll need a case statement for that.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: