From 17657cce97df8ec2f0dd833b9dd5154de55333eb Mon Sep 17 00:00:00 2001 From: Matyas Selmeci Date: Mon, 5 Aug 2024 11:13:10 -0500 Subject: [PATCH] Fix quoting issue in the last eval statement in set_var; also check for invalid variable names Don't add extra quoting to the setting of the default value -- that causes disconnection issues for some reason --- 10-setup-htcondor.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/10-setup-htcondor.sh b/10-setup-htcondor.sh index 28f50e7..aa6964d 100755 --- a/10-setup-htcondor.sh +++ b/10-setup-htcondor.sh @@ -25,6 +25,14 @@ set_var() { if [ -z "$var_name" ]; then # empty line return 0 + elif [[ ! $var_name =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then + printf "Skipping invalid variable name '%s'\n" "$var_name" 1>&2 + if [[ $var_req == Y ]]; then + # probably never happens but just in case... + printf "Variable named '%s' was required; exiting\n" "$var_name" 1>&2 + exit 1 + fi + return 0 fi var_name_len=${#var_name} @@ -38,6 +46,7 @@ set_var() { # no default, do not set return 0 else + # Adding extra quoting here caused startd disconnection issues for some reason eval var_val=$var_def fi fi @@ -80,8 +89,10 @@ set_var() { fi fi - # define it for future use - eval "$var_name='$var_val'" + # define it for future use; make sure it's properly quoted + local statement="$(printf "%q=%q" "$var_name" "$var_val")" + echo "setting var: $statement" + eval "$statement" return 0 }