fix: Sanitize filename (#577)

This commit is contained in:
Kroese 2024-01-19 04:17:09 +01:00 committed by GitHub
parent fab776764f
commit b908c1118d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,8 +11,12 @@ else
fi fi
if [ -n "$URL" ]; then if [ -n "$URL" ]; then
PURL="${URL%%\?*}" BASE=$(basename "$URL" .pat)
BASE=$(basename "$PURL" .pat) if [ ! -f "$STORAGE/$BASE.system.img" ]; then
BASE=$(basename "${URL%%\?*}" .pat)
: "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
fi
fi fi
if [[ -f "$STORAGE/$BASE.boot.img" ]] && [[ -f "$STORAGE/$BASE.system.img" ]]; then if [[ -f "$STORAGE/$BASE.boot.img" ]] && [[ -f "$STORAGE/$BASE.system.img" ]]; then
@ -37,8 +41,9 @@ fi
[ -z "$URL" ] && URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat" [ -z "$URL" ] && URL="$DL/release/7.2.1/69057-1/DSM_VirtualDSM_69057.pat"
PURL="${URL%%\?*}" BASE=$(basename "${URL%%\?*}" .pat)
BASE=$(basename "$PURL" .pat) : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
if [[ "$URL" != "file://$STORAGE/$BASE.pat" ]]; then if [[ "$URL" != "file://$STORAGE/$BASE.pat" ]]; then
rm -f "$STORAGE/$BASE.pat" rm -f "$STORAGE/$BASE.pat"
@ -169,7 +174,7 @@ fi
rm -rf "$TMP" && mkdir -p "$TMP" rm -rf "$TMP" && mkdir -p "$TMP"
info "Install: Downloading $(basename "$PURL")..." info "Install: Downloading $BASE.pat..."
PAT="/$BASE.pat" PAT="/$BASE.pat"
rm -f "$PAT" rm -f "$PAT"
@ -315,7 +320,6 @@ else
fi fi
rm -rf "$MOUNT" rm -rf "$MOUNT"
echo "$BASE" > "$STORAGE/dsm.ver" echo "$BASE" > "$STORAGE/dsm.ver"
if [[ "$URL" == "file://$STORAGE/$BASE.pat" ]]; then if [[ "$URL" == "file://$STORAGE/$BASE.pat" ]]; then
@ -325,7 +329,6 @@ else
fi fi
mv -f "$BOOT" "$STORAGE/$BASE.boot.img" mv -f "$BOOT" "$STORAGE/$BASE.boot.img"
rm -rf "$TMP" rm -rf "$TMP"
{ set +x; } 2>/dev/null { set +x; } 2>/dev/null