commit:     83fde0f92f7686ec40da426053452f87e25a6be6
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jul 27 00:14:15 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 30 07:30:37 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=83fde0f9

Don't expand parameters as $@ for assignment to scalars

Per SC2124, though bash does promise that this approach results in the
elements being joined by a space, it is often a code smell. Instead,
either explicitly join the positional parameters as "$*" or expand
whichever parameter is relevant.

Also, for some of the functions in bin/phase-helpers.sh, check the
positional parameters with has() first, rather than join and proceed to
check by way of an unquoted variable expansion, which may then result in
unintentional pathname expansion (SC2086).

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/bashrc-functions.sh |  6 +++---
 bin/phase-helpers.sh    | 33 +++++++++++++++++++++------------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/bin/bashrc-functions.sh b/bin/bashrc-functions.sh
index 7d6aab5443..93272df243 100644
--- a/bin/bashrc-functions.sh
+++ b/bin/bashrc-functions.sh
@@ -31,14 +31,14 @@ __strip_duplicate_slashes() {
 KV_major() {
        [[ -z ${1} ]] && return 1
 
-       local KV=$@
+       local KV=$1
        echo "${KV%%.*}"
 }
 
 KV_minor() {
        [[ -z ${1} ]] && return 1
 
-       local KV=$@
+       local KV=$1
        KV=${KV#*.}
        echo "${KV%%.*}"
 }
@@ -46,7 +46,7 @@ KV_minor() {
 KV_micro() {
        [[ -z ${1} ]] && return 1
 
-       local KV=$@
+       local KV=$1
        KV=${KV#*.*.}
        echo "${KV%%[^[:digit:]]*}"
 }

diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 26f8c6f903..ca85bec97c 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -112,32 +112,41 @@ docinto() {
 }
 
 insopts() {
-       export INSOPTIONS="$@"
+       local IFS
 
-       # `install` should never be called with '-s' ...
-       has -s ${INSOPTIONS} && die "Never call insopts() with -s"
+       if has -s "$@"; then
+               die "Never call insopts() with -s"
+       else
+               export INSOPTIONS=$*
+       fi
 }
 
 diropts() {
-       export DIROPTIONS="$@"
+       local IFS
+
+       export DIROPTIONS=$*
 }
 
 exeopts() {
-       export EXEOPTIONS="$@"
+       local IFS
 
-       # `install` should never be called with '-s' ...
-       has -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
+       if has -s "$@"; then
+               die "Never call exeopts() with -s"
+       else
+               export EXEOPTIONS=$*
+       fi
 }
 
 libopts() {
+       local IFS
+
        if ! ___eapi_has_dolib_libopts; then
                die "'${FUNCNAME}' has been banned for EAPI '${EAPI}'"
+       elif has -s "$@"; then
+               die "Never call libopts() with -s"
+       else
+               export LIBOPTIONS=$*
        fi
-
-       export LIBOPTIONS="$@"
-
-       # `install` should never be called with '-s' ...
-       has -s ${LIBOPTIONS} && die "Never call libopts() with -s"
 }
 
 docompress() {

Reply via email to