]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ktest.pl: Prevent recursion of default variable options
authorSteven Rostedt <rostedt@goodmis.org>
Fri, 18 Jul 2025 20:18:44 +0000 (16:18 -0400)
committerSteven Rostedt <rostedt@goodmis.org>
Mon, 21 Jul 2025 20:31:04 +0000 (16:31 -0400)
If a default variable contains itself, do not recurse on it.

For example:

  ADD_CONFIG := ${CONFIG_DIR}/temp_config
  DEFAULTS
  ADD_CONFIG = ${CONFIG_DIR}/default_config ${ADD_CONFIG}

The above works because the temp variable ADD_CONFIG (is a temp because it
is created with ":=") is already defined, it will be substituted in the
variable option. But if it gets commented out:

  # ADD_CONFIG := ${CONFIG_DIR}/temp_config
  DEFAULTS
  ADD_CONFIG = ${CONFIG_DIR}/default_config ${ADD_CONFIG}

Then the above will go into a recursive loop where ${ADD_CONFIG} will
get replaced with the current definition of ADD_CONFIG which contains the
${ADD_CONFIG} and that will also try to get converted. ktest.pl will error
after 100 attempts of recursion and fail.

When replacing a variable with the default variable, if the default
variable contains itself, do not replace it.

Cc: "John Warthog9 Hawley" <warthog9@kernel.org>
Cc: Dhaval Giani <dhaval.giani@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/20250718202053.732189428@kernel.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
tools/testing/ktest/ktest.pl

index 95e62929cda7d9d5148cf27ae0772a0cd09e5f4c..3a679259f4e280bdd1fcad70006fff03132962ff 100755 (executable)
@@ -1394,7 +1394,10 @@ sub __eval_option {
        # If a variable contains itself, use the default var
        if (($var eq $name) && defined($opt{$var})) {
            $o = $opt{$var};
-           $retval = "$retval$o";
+           # Only append if the default doesn't contain itself
+           if ($o !~ m/\$\{$var\}/) {
+               $retval = "$retval$o";
+           }
        } elsif (defined($opt{$o})) {
            $o = $opt{$o};
            $retval = "$retval$o";