From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 2307F15807A for ; Fri, 06 Jun 2025 22:02:27 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 080F4343137 for ; Fri, 06 Jun 2025 22:02:27 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 79AE21103DD; Fri, 06 Jun 2025 22:02:22 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 6E9921103DD for ; Fri, 06 Jun 2025 22:02:22 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id F222234309B for ; Fri, 06 Jun 2025 22:02:21 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 67BD22903 for ; Fri, 06 Jun 2025 22:02:20 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1749247337.bf17d5963cead8c930d3e996f976e57b99d839f8.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/bashrc-functions.sh X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: bf17d5963cead8c930d3e996f976e57b99d839f8 X-VCS-Branch: master Date: Fri, 06 Jun 2025 22:02:20 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: be791f41-827d-4d74-b311-148a1fbc4cf8 X-Archives-Hash: d4a0a5b9b73859682d9534ce0c421cbf commit: bf17d5963cead8c930d3e996f976e57b99d839f8 Author: Kerin Millar plushkava net> AuthorDate: Fri Jun 6 21:02:58 2025 +0000 Commit: Sam James gentoo org> CommitDate: Fri Jun 6 22:02:17 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=bf17d596 bashrc-functions.sh: have register_{die,success}_hook() validate their parameters Presently, the register_die_hook() and register_success_hook() functions make use of the contains_word() function in order to determine whether the 'EBUILD_DEATH_HOOKS' and 'EBUILD_SUCCESS_HOOKS' variables need to be extended. This is so as to ensure that the same hook cannot be added more than once. # Adds a hook for the my_cleanup function. register_die_hook my_cleanup # This is a no-op because the hook is already registered. register_die_hook my_cleanup However, the contains_word() function will always return false where its first argument contains whitespace, for which there is a good reason. # We may consider this to be a scalar variable comprising four words. wordlist='foo bar baz quux' # Thus, it would not be appropriate for this to return true. contains_word 'bar baz' "${wordlist}" So far, so good. However, one must then consider that, whenever contains_word() returns false, it is effectively granting permission for the hook to be added again, giving rise to the following edge case. # Two hooks will be registered by the names of "bar" and "baz". # Not an intended use case; two arguments should be given. register_die_hook 'bar baz' # This will register both again, despite having been added already. register_die_hook 'bar baz' To remedy this, have the register_die_hook() and register_success_hook() functions validate their parameters. The nature of the validation is straightforward: if a given parameter be empty, or contain any whitespace, then it shall be considered as invalid and disregarded. Though such cases should be vanishingly rare in practice, I would have liked to raise a warning for them. However, /etc/portage/bashrc is sourced so often that, barring an improved warning mechanism, it is currently impractical. Fixes: 3b0150e488972b02c45c71192507300d823a361f See-also: 4a4631eef7186c29668a8c049d988b61469940fd Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/bashrc-functions.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/bashrc-functions.sh b/bin/bashrc-functions.sh index 9b8b74dc7e..568f16da6c 100644 --- a/bin/bashrc-functions.sh +++ b/bin/bashrc-functions.sh @@ -6,7 +6,9 @@ register_die_hook() { local hook for hook; do - if ! contains_word "${hook}" "${EBUILD_DEATH_HOOKS}"; then + if [[ ${hook} != +([![:space:]]) ]]; then + : + elif ! contains_word "${hook}" "${EBUILD_DEATH_HOOKS}"; then export EBUILD_DEATH_HOOKS+=" ${hook}" fi done @@ -16,7 +18,9 @@ register_success_hook() { local hook for hook; do - if ! contains_word "${hook}" "${EBUILD_SUCCESS_HOOKS}"; then + if [[ ${hook} != +([![:space:]]) ]]; then + : + elif ! contains_word "${hook}" "${EBUILD_SUCCESS_HOOKS}"; then export EBUILD_SUCCESS_HOOKS+=" ${hook}" fi done