From 70cc99bccf163502c9cc9440ba085471a320d8d3 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Fri, 28 Feb 2020 11:00:18 +0100 Subject: [PATCH] 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 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1054 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki Reviewed-by: Shuhei Matsumoto --- test/nvmf/target/invalid.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/nvmf/target/invalid.sh b/test/nvmf/target/invalid.sh index 3f7b48c1f..e578e5b34 100755 --- a/test/nvmf/target/invalid.sh +++ b/test/nvmf/target/invalid.sh @@ -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" }