mirror of
https://github.com/kaboomserver/server.git
synced 2025-04-22 09:23:42 -04:00
refactor: split common URL logic into download_with_args
This commit is contained in:
parent
00956436dc
commit
d73ce8a1f6
5 changed files with 12 additions and 10 deletions
scripts
|
@ -41,12 +41,11 @@ check_path() {
|
|||
case "$1" in
|
||||
"/"*) echo "Attempted path traversal: $1 is absolute"
|
||||
return 1;;
|
||||
|
||||
*);; # Safe
|
||||
esac
|
||||
|
||||
case "$rpath" in
|
||||
"$_EXEC_PATH/"*);; # Safe
|
||||
|
||||
*) echo "Attempted path traversal: $1 is outside current directory"
|
||||
return 1;;
|
||||
esac
|
||||
|
|
|
@ -42,12 +42,20 @@ require_args() {
|
|||
tmp=""
|
||||
done
|
||||
}
|
||||
|
||||
download_with_args() {
|
||||
require_args url
|
||||
|
||||
download "${arg_url:?}" "$1"
|
||||
}
|
||||
|
||||
download_type() {
|
||||
# Calling the function with _download_type_"$1" opens up the
|
||||
# possibility for users to run arbitrary commands, so we must
|
||||
# manually handle the type.
|
||||
|
||||
#
|
||||
# Since the args are part of the function's stdin, they will be
|
||||
# be propagated into the _download_type_... functions.
|
||||
case "$1" in
|
||||
"url") _download_type_url "$2";;
|
||||
"zip") _download_type_zip "$2";;
|
||||
|
|
|
@ -2,7 +2,5 @@
|
|||
|
||||
_download_type_url() {
|
||||
read_args url
|
||||
require_args url
|
||||
|
||||
download "${arg_url:?}" "$1"
|
||||
download_with_args "$@"
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ _download_type_zip() {
|
|||
zip_path="$(mktemp --suffix=.zip)"
|
||||
|
||||
exitcode=0
|
||||
download "${arg_url:?}" "$zip_path" || exitcode=$?
|
||||
download_with_args "$zip_path" || exitcode=$?
|
||||
if [ $exitcode != 0 ]; then
|
||||
rm -f "$zip_path" 2>/dev/null
|
||||
return $exitcode
|
||||
|
|
|
@ -52,8 +52,5 @@ _parse_downloads | while read -r path; read -r type; read -r args; do
|
|||
fi
|
||||
|
||||
debug "download_type: type=$type; args=$args"
|
||||
|
||||
# Since the args are part of the function's stdin, they will be
|
||||
# be propagated up.
|
||||
echo "$args" | download_type "$type" "$path"
|
||||
done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue