From: Sergei Trofimovich <slyfox@gentoo.org>
To: Gentoo Development <gentoo-dev@lists.gentoo.org>
Subject: [gentoo-dev] Lexicographical bash comparison mistakes: things to fix
Date: Sun, 12 Jan 2020 12:09:10 +0000 [thread overview]
Message-ID: <20200112120910.42736cd2@sf> (raw)
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 other threads:[~2020-01-12 12:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200112120910.42736cd2@sf \
--to=slyfox@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox