Commit 23ce8192 by Eric Coissac

Protect local variable of function using eval with potential border

effects
parent f9c10d50
Pipeline #18 skipped
......@@ -46,23 +46,23 @@ function pushvalue() {
}
function popvalue() {
local STACK="${1}"
local __popvalue_STACK="${1}"
shift
if [[ ! -z "${1}" ]]; then
local COMMAND="${1}="
local __popvalue_COMMAND="${1}="
else
local COMMAND="echo "
local __popvalue_COMMAND="echo "
fi
local s=$(stacksize ${STACK})
local s=$(stacksize ${__popvalue_STACK})
if (( s==0 )); then
return 1
fi
local valcmd="${COMMAND}\${${STACK}[\$(( s - 1 ))]}"
eval $valcmd
valcmd="unset ${STACK}[\$(( s - 1 ))]"
eval $valcmd
local __popvalue_valcmd="${__popvalue_COMMAND}\${${__popvalue_STACK}[\$(( s - 1 ))]}"
eval $__popvalue_valcmd
valcmd="unset ${__popvalue_STACK}[\$(( s - 1 ))]"
eval $__popvalue_valcmd
return 0
}
......@@ -75,12 +75,12 @@ function getbasetmpdir() {
}
function tempdirectory() {
local minsize="0"
local __tempdirectory_minsize="0"
if [[ ! -z "${1}" ]]; then
local COMMAND="${1}="
local __tempdirectory_COMMAND="${1}="
else
local COMMAND="echo "
local __tempdirectory_COMMAND="echo "
fi
shift
......@@ -94,27 +94,27 @@ function tempdirectory() {
fi
if [[ ! -z "${1}" ]] ; then
minsize="${1}"
__tempdirectory_minsize="${1}"
fi
local nbase=$(stacksize __LECABASHLIB_BASETMPDIRSTACK__)
local i=0
local __tempdirectory_nbase=$(stacksize __LECABASHLIB_BASETMPDIRSTACK__)
local __tempdirectory_i=0
while (( i < nbase )) && \
(( $(availabledisk "${__LECABASHLIB_BASETMPDIRSTACK__[$i]}") < minsize )) ; do
i=$(( i + 1 ))
while (( __tempdirectory_i < __tempdirectory_nbase )) && \
(( $(availabledisk "${__LECABASHLIB_BASETMPDIRSTACK__[$i]}") < __tempdirectory_minsize )) ; do
__tempdirectory_i=$(( __tempdirectory_i + 1 ))
done
if (( i >= nbase )) ; then
if (( __tempdirectory_i >= __tempdirectory_nbase )) ; then
return 1
fi
local basedir="${__LECABASHLIB_BASETMPDIRSTACK__[$i]}"
local directory=$(mktemp -d "${basedir%/}/${__LECABASHLIB_TMPBASENAME__}")
pushvalue __LECABASHLIB_TMPDIRSTACK__ "$directory"
local __tempdirectory_basedir="${__LECABASHLIB_BASETMPDIRSTACK__[$__tempdirectory_i]}"
local __tempdirectory_directory=$(mktemp -d "${__tempdirectory_basedir%/}/${__LECABASHLIB_TMPBASENAME__}")
pushvalue __LECABASHLIB_TMPDIRSTACK__ "$__tempdirectory_directory"
local valcmd="${COMMAND}${directory}"
eval $valcmd
local __tempdirectory_valcmd="${__tempdirectory_COMMAND}${__tempdirectory_directory}"
eval $__tempdirectory_valcmd
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment