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: Michal Berger <michalx.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1054
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Michal Berger 2020-02-28 11:00:18 +01:00 committed by Tomasz Zawadzki
parent 23f78f22cf
commit 70cc99bccf

View File

@ -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"
}