Commit 70cc99bc authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

test/nvmf: Sanitize random string



In case the random string beggins with `-` (still a valid ascii char
that nvme supports) the rpc.py arg parser will treat it as an
additional argument instead of actual subsystem value.

To mitigate, escape the `-` in case it's the char that starts the
string.

Fixes: 1240

Change-Id: I07bd8134fb9fc16234e72e9ebd27e2b6b90d6b62
Signed-off-by: default avatarMichal Berger <michalx.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1054


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 23f78f22
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ gen_random_s () {
	for (( ll = 0; ll < length; ll++ )); do
		string+="$(echo -e "\x$(printf '%x' "${chars[RANDOM % ${#chars[@]}]}")")"
	done
	# Be nice to rpc.py's arg parser and escape `-` in case it's a first character
	if [[ ${string::1} == "-" ]]; then
		string=${string/-/\\-}
	fi
	echo "$string"
}