From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id D8C50138350 for ; Sun, 12 Jan 2020 12:09:20 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E8DD5E0CBF; Sun, 12 Jan 2020 12:09:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id CE5EBE0CA6 for ; Sun, 12 Jan 2020 12:09:14 +0000 (UTC) Received: from sf (tunnel547699-pt.tunnel.tserv1.lon2.ipv6.he.net [IPv6:2001:470:1f1c:3e6::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: slyfox) by smtp.gentoo.org (Postfix) with ESMTPSA id 84E5B34DFAC for ; Sun, 12 Jan 2020 12:09:13 +0000 (UTC) Date: Sun, 12 Jan 2020 12:09:10 +0000 From: Sergei Trofimovich To: Gentoo Development Subject: [gentoo-dev] Lexicographical bash comparison mistakes: things to fix Message-ID: <20200112120910.42736cd2@sf> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archives-Salt: fba1b7d8-7f94-46ee-a36a-90dd5b6d23d6 X-Archives-Hash: 1ccdf0e8758ed760b4ae598d30af250d 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 ... ... 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