A few ebuilds use bash '[[ ${foo} < ${bar} ]]' comparison to compare
numbers and package versions.

In bash '<' is for lexicographical string comparison (see man bash
'CONDITIONAL EXPRESSIONS' section). It's almost never what
you want:

    $ [[ 1.2.3 < 1.2.3 ]] && echo yes || echo no
    no # ok
    $ [[ 1.2.9 < 1.2.3 ]] && echo yes || echo no
    no # ok
    $ [[ 1.2.9 < 1.2.10 ]] && echo yes || echo no
    no # whoops

A very crude grep shows many affected packages:
    $ git grep -E '\[\[.*[<>]\s*[0-9]+.*\]\]' | cat
    app-misc/unfoo/unfoo-1.0.8.ebuild:  elif [[ ${REPLACING_VERSIONS} < 1.0.7 
]]; then
    dev-db/libzdb/libzdb-3.1-r1.ebuild: if  [[ $(gcc-version) < 4.1 ]];then
    dev-db/libzdb/libzdb-3.1.ebuild:    if  [[ $(gcc-version) < 4.1 ]];then
    eclass/kernel-2.eclass:     if [[ ${K_SYMLINK} > 0 ]]; then
    eclass/kernel-2.eclass:                     if [[ ${KV_MAJOR} -ge 3 || 
${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.24 ]] ; then
    eclass/kernel-2.eclass:             if [[ ${KV_MAJOR} -ge 3 || 
${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.28 ]]; then
    eclass/kernel-2.eclass:     if [[ -n ${KV_MINOR} &&  
${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} < 2.6.27 ]] ; then
    ... <list goes on and on> ...

Some of them are benign like '[[ ${foo} > 0 ]]': I think it's still worth 
fixing them.
Some of them are worse like [[ $(gcc-version) < 4.1 ]]: gcc-version=10 will 
break here.

I've created a tracker and dumped a few suspects there:
    https://bugs.gentoo.org/705240

I'm sure there are more creative ways to hide version (or just number)
compare behind lexicographical string comparison. If you have an idea how
grep those out please do report and fix them :)

Thank you!

-- 

  Sergei

Reply via email to