commit: 1b20070166fdb08b28bebd7db66171329f760f77
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jul 27 21:49:37 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 30 08:14:24 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1b200701
phase-helpers.sh: build decompression command from __unpack_tar() args
This does away with the unquoted expansion of $1 but there is more to it
than merely placating shellcheck. Before, it was possible for a
user-specified command to induce pathname expansion, for which there is
no compelling use case. Now, it is impossible for this to occur. For
example, specifying PORTAGE_BUNZIP2_COMMAND="/bin/*" will now result in
attempting to execute a binary by that name, as opposed to expanding all
the files in /bin as distinct words then trying to execute a simple
command beginning with whatever the first of those happens to be.
Further, given a blank command - such as PORTAGE_BUNZIP2_COMMAND=" " -
portage would previously attempt to execute a command named -c. Now, it
will instead fall back to using PORTAGE_BZIP2_COMMAND. Should that also
yield a blank command, an exception shall be thrown.
It should be noted that the act of localising IFS is sufficient to
guarantee the default behaviour, provided that no assignment occurs.
That is, word splitting shall be performed as if a value of $' \t\n'
were in effect.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/phase-helpers.sh | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 3c101a787c..86280a41d5 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -328,6 +328,7 @@ use_enable() {
unpack() {
local created_symlink
local suffix_known
+ local -a bzip2_cmd
local basename
local srcdir
local suffix
@@ -346,9 +347,23 @@ unpack() {
inner_suffix=${inner_suffix,,}
fi
if [[ ${inner_suffix} == tar ]]; then
- $1 -c -- "${srcdir}${f}" | tar xof -
+ "$@" -c -- "${srcdir}${f}" | tar xof -
else
- $1 -c -- "${srcdir}${f}" > "${basename%.*}"
+ "$@" -c -- "${srcdir}${f}" > "${basename%.*}"
+ fi
+ }
+
+ __compose_bzip2_cmd() {
+ local IFS
+
+ read -rd '' -a bzip2_cmd <<<"${PORTAGE_BUNZIP2_COMMAND}"
+ if (( ! ${#bzip2_cmd[@]} )); then
+ read -rd '' -a bzip2_cmd <<<"${PORTAGE_BZIP2_COMMAND}"
+ if (( ${#bzip2_cmd[@]} )); then
+ bzip2_cmd+=( -d )
+ else
+ die "unpack: both PORTAGE_BUNZIP2_COMMAND and
PORTAGE_BZIP2_COMMAND specify null commands"
+ fi
fi
}
@@ -410,7 +425,8 @@ unpack() {
tar xozf "${srcdir}${f}"
;;
tbz|tbz2)
-
${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "${srcdir}${f}" |
tar xof -
+ (( ${#bzip2_cmd[@]} )) || __compose_bzip2_cmd
+ "${bzip2_cmd[@]}" -c -- "${srcdir}${f}" | tar
xof -
;;
zip|jar)
# unzip will interactively prompt under some
error conditions,
@@ -419,10 +435,11 @@ unpack() {
unzip -qo "${srcdir}${f}" </dev/null
;;
gz|z)
- __unpack_tar "gzip -d"
+ __unpack_tar gzip -d
;;
bz2|bz)
- __unpack_tar
"${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
+ (( ${#bzip2_cmd[@]} )) || __compose_bzip2_cmd
+ __unpack_tar "${bzip2_cmd[@]}"
;;
7z)
local my_output
@@ -465,10 +482,10 @@ unpack() {
fi
;;
lzma)
- __unpack_tar "lzma -d"
+ __unpack_tar lzma -d
;;
xz)
- __unpack_tar "xz -T$(___makeopts_jobs) -d"
+ __unpack_tar xz -T"$(___makeopts_jobs)" -d
;;
txz)
XZ_OPT="-T$(___makeopts_jobs)" tar xof
"${srcdir}${f}"