public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] Lexicographical bash comparison mistakes: things to fix
@ 2020-01-12 12:09 Sergei Trofimovich
  0 siblings, 0 replies; only message in thread
From: Sergei Trofimovich @ 2020-01-12 12:09 UTC (permalink / raw
  To: Gentoo Development

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-12 12:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-12 12:09 [gentoo-dev] Lexicographical bash comparison mistakes: things to fix Sergei Trofimovich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox