commit: 0b4f4a0bf19b6a069a74883bf8ad5ba4be3ed0f4
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Jun 27 06:06:01 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jun 28 02:30:21 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=0b4f4a0b
save-ebuild-env-sh: refrain from assigning to and unsetting x
Presently, the __save_ebuild_env() function uses the 'x' variable to
iterate over various function names before proceeding to unset it. To do
so is inadvisable because variables are dynamically scoped in bash and
there may be no guarantee that 'x' wasn't already declared. Hence, the
use of the unset builtin can be dangerous, since it can have the effect
of unmasking a variable from a previous scope.
$ var=1
$ x() { local var=2; y; }
$ y() { var=3; unset var; declare -p var; }
$ x
declare -- var="1"
Address this issue by instead having the applicable for loop use the
special '_' parameter as a topic variable.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/save-ebuild-env.sh | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
index f39c24eb90..5d5d25bbd7 100644
--- a/bin/save-ebuild-env.sh
+++ b/bin/save-ebuild-env.sh
@@ -42,12 +42,11 @@ __save_ebuild_env() (
# There's no need to bloat environment.bz2 with internally defined
# functions and variables, so filter them out if possible.
- for x in pkg_setup pkg_nofetch src_unpack src_prepare src_configure \
+ for _ in pkg_setup pkg_nofetch src_unpack src_prepare src_configure \
src_compile src_test src_install pkg_preinst pkg_postinst \
pkg_prerm pkg_postrm pkg_config pkg_info pkg_pretend ; do
- unset -f default_${x} __eapi{0,1,2,4,6,8}_${x}
+ unset -f default_${_} __eapi{0,1,2,4,6,8}_${_}
done
- unset x
unset -f assert __assert_sigpipe_ok \
__dump_trace die \