commit:     1b7a2a9c8544b5a2ed0168d8c0665bbf11ac66a0
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Feb  4 22:38:47 2026 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb  6 01:45:14 2026 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=1b7a2a9c

test-functions: handle parameters beyond $9 in iterate_tests()

The iterate_tests() function has a serious bug, whereby positional
parameters beyond "$9" are not actually dereferenced.

Though the test-functions script currently does nothing to induce this
bug, it would only require for a test case to be added that defines
sufficiently long parameter slices for the situation to change.

The root cause is that parameters such as "$10", "$11", "$12" may
undergo expansion. Note that the effect of expanding "$10" is to expand
"$1", along with a trailing "0". Address this issue by enclosing the
digits within curly braces. Thus, "${10}", "${11}", "${12} and so on.

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

 test-functions | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test-functions b/test-functions
index 989c0e9..020f348 100755
--- a/test-functions
+++ b/test-functions
@@ -1213,10 +1213,10 @@ iterate_tests() {
                code="callback"
                j=1
                while [ "$((j += 1))" -le "${slice_width}" ]; do
-                       if eval "[ \"\$${j}\" = N/A ]"; then
+                       if eval "[ \"\${$j}\" = N/A ]"; then
                                break
                        else
-                               code="${code} \"\$${j}\""
+                               code="${code} \"\${$j}\""
                        fi
                done
                eval "${code}"

Reply via email to