Skip to content

Commit

Permalink
Merge pull request #174 from matyasselmeci/pr/fix-eval-quoting
Browse files Browse the repository at this point in the history
Fix quoting issue in the last eval statement in set_var; also check for invalid variable names
  • Loading branch information
matyasselmeci authored Aug 13, 2024
2 parents accd444 + 17657cc commit 2d45355
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions 10-setup-htcondor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 2d45355

Please sign in to comment.