Skip to content

Commit

Permalink
easyrsa_mktemp(): Make variable names more unique to avoid conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Jun 2, 2024
1 parent c7f6927 commit d0bf2ba
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions easyrsa3/easyrsa
Original file line number Diff line number Diff line change
Expand Up @@ -843,22 +843,21 @@ easyrsa_mkdir() {
# will hide error message and verbose messages
# from easyrsa_mktemp()
easyrsa_mktemp() {
[ "$#" = 1 ] || die "\
easyrsa_mktemp - input error"
[ "$#" = 1 ] || die "easyrsa_mktemp - input error"

# session directory must exist
[ "$secured_session" ] || die "\
easyrsa_mktemp - Temporary session undefined (--tmp-dir)"

# Assign internal temp-file name
t="${secured_session}/temp.${mktemp_counter}"
tmp_fname="${secured_session}/temp.${mktemp_counter}"

# Create shotfile
for h in x y z; do
shotfile="${t}.${h}"
for ext_shot in x y z; do
shotfile="${tmp_fname}.${ext_shot}"
if [ -e "$shotfile" ]; then
verbose "\
easyrsa_mktemp: shot-file EXISTS: $shotfile"
easyrsa_mktemp: shotfile EXISTS: $shotfile"
continue
else
printf "" > "$shotfile" || die "\
Expand All @@ -868,12 +867,12 @@ easyrsa_mktemp: create shotfile failed (1) $1"
# subshells do not update mktemp_counter,
# which is why this extension is required.
# Current max required is 3 attempts
for i in 1 2 3 4 5 6 7 8 9; do
want_tmp_file="${t}.${i}"
for ext_try in 1 2 3 4 5 6 7 8 9; do
want_tmp_file="${tmp_fname}.${ext_try}"

# Warn to error log file for max reached
[ "$EASYRSA_MAX_TEMP" -gt "$i" ] || print "\
Max temp-file limit $i, hit for: $1" >> "$easyrsa_err_log"
[ "$EASYRSA_MAX_TEMP" -gt "$ext_try" ] || print "\
Max temp-file limit $ext_try, hit for: $1" >> "$easyrsa_err_log"

if [ -e "$want_tmp_file" ]; then
verbose "\
Expand All @@ -886,19 +885,21 @@ easyrsa_mktemp: temp-file EXISTS: $want_tmp_file"
fi

if mv "$shotfile" "$want_tmp_file"; then
# Update counter
mktemp_counter="$(( mktemp_counter + 1 ))"

# Assign external temp-file name
if force_set_var "$1" "$want_tmp_file"
then
verbose "\
easyrsa_mktemp: $1 OK: $want_tmp_file"
:: easyrsa_mktemp: $1 OK: $want_tmp_file"

if [ "$easyrsa_host_os" = win ]; then
set +o noclobber
fi
unset -v want_tmp_file shotfile

# Update counter
mktemp_counter="$((mktemp_counter+1))"

unset -v shotfile ext_shot \
want_tmp_file ext_try
return
else
die "\
Expand All @@ -912,7 +913,7 @@ easyrsa_mktemp - force_set_var $1 failed"

# In case of subshell abuse, report to error log
err_msg="\
easyrsa_mktemp - failed for: $1 @ attempt=$i
easyrsa_mktemp - failed for: $1 @ attempt=$ext_try
want_tmp_file: $want_tmp_file"
print "$err_msg" >> "$easyrsa_err_log"
die "$err_msg"
Expand Down

0 comments on commit d0bf2ba

Please sign in to comment.