[PATCH] livepatch/selftests: use "$@" to preserve argument list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The livepatch selftest functions.sh library uses "$*" and an
intermediate variable to extract and then pass arguments from function
to function call.  The effect of this combination is that the argument
list is flattened into a single argument.  Sometimes this is benign, but
in cases like __load_mod(), the modprobe invocation will interpret all
the module parameters as a single parameter.

Drop the intermediate variable and use the "$@" special parameter as
described in the bash manual.

Link: https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters
Signed-off-by: Joe Lawrence <joe.lawrence@xxxxxxxxxx>

---

Note: found while creating new selftests, but this problem does not
      affect the current set of tests that currently live in
      livepatching/for-5.1/atomic-replace.

And the following is not needed for commit msg, but was a simple test to
demo this for myself:

  -- test.sh --
  #!/bin/bash

  function bar()  { echo -e "1=$1\n2=$2\n3=$3"; }
  function foo1() { local args="$*"; bar "$args"; }
  function foo2() { bar "$*"; }
  function foo3() { local args="$@"; bar "$args"; }
  function foo4() { bar "$@"; }

  echo "-- foo1"; foo1 one two three
  echo "-- foo2"; foo2 one two three
  echo "-- foo3"; foo3 one two three
  echo "-- foo4"; foo4 one two three

  % ./test.sh
  -- foo1
  1=one two three
  2=
  3=
  -- foo2
  1=one two three
  2=
  3=
  -- foo3
  1=one two three
  2=
  3=
  -- foo4
  1=one
  2=two
  3=three

 .../testing/selftests/livepatch/functions.sh  | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index c7b9fb45d7c9..30195449c63c 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -55,11 +55,10 @@ function is_livepatch_mod() {
 
 function __load_mod() {
 	local mod="$1"; shift
-	local args="$*"
 
-	local msg="% modprobe $mod $args"
+	local msg="% modprobe $mod $*"
 	log "${msg%% }"
-	ret=$(modprobe "$mod" "$args" 2>&1)
+	ret=$(modprobe "$mod" "$@" 2>&1)
 	if [[ "$ret" != "" ]]; then
 		die "$ret"
 	fi
@@ -75,12 +74,11 @@ function __load_mod() {
 #	params  - module parameters to pass to modprobe
 function load_mod() {
 	local mod="$1"; shift
-	local args="$*"
 
 	is_livepatch_mod "$mod" &&
 		die "use load_lp() to load the livepatch module $mod"
 
-	__load_mod "$mod" "$args"
+	__load_mod "$mod" "$@"
 }
 
 # load_lp_nowait(modname, params) - load a kernel module with a livepatch
@@ -89,12 +87,11 @@ function load_mod() {
 #	params  - module parameters to pass to modprobe
 function load_lp_nowait() {
 	local mod="$1"; shift
-	local args="$*"
 
 	is_livepatch_mod "$mod" ||
 		die "module $mod is not a livepatch"
 
-	__load_mod "$mod" "$args"
+	__load_mod "$mod" "$@"
 
 	# Wait for livepatch in sysfs ...
 	loop_until '[[ -e "/sys/kernel/livepatch/$mod" ]]' ||
@@ -106,9 +103,8 @@ function load_lp_nowait() {
 #	params  - module parameters to pass to modprobe
 function load_lp() {
 	local mod="$1"; shift
-	local args="$*"
 
-	load_lp_nowait "$mod" "$args"
+	load_lp_nowait "$mod" "$@"
 
 	# Wait until the transition finishes ...
 	loop_until 'grep -q '^0$' /sys/kernel/livepatch/$mod/transition' ||
@@ -120,11 +116,10 @@ function load_lp() {
 #	params  - module parameters to pass to modprobe
 function load_failing_mod() {
 	local mod="$1"; shift
-	local args="$*"
 
-	local msg="% modprobe $mod $args"
+	local msg="% modprobe $mod $*"
 	log "${msg%% }"
-	ret=$(modprobe "$mod" "$args" 2>&1)
+	ret=$(modprobe "$mod" "$@" 2>&1)
 	if [[ "$ret" == "" ]]; then
 		die "$mod unexpectedly loaded"
 	fi
-- 
2.20.1




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux