Run a virtual iPhone on an Apple Silicon Mac.
Swift
vm: validate restore and switch backup names (#210)
TastyHeadphones71b8f8e53b67
diff --git a/scripts/vm_restore.sh b/scripts/vm_restore.shindex f2241d65..305a874b 100755--- a/scripts/vm_restore.sh+++ b/scripts/vm_restore.sh@@ -11,6 +11,15 @@ BACKUPS_DIR="${BACKUPS_DIR:-vm.backups}"NAME="${NAME:-}"FORCE="${FORCE:-0}"+validate_backup_name() {+ local name="$1"+ local label="${2:-NAME}"+ if [[ "$name" == */* || "$name" == .* ]]; then+ echo "ERROR: ${label} must be a simple identifier (no slashes or leading dots)."+ exit 1+ fi+}+# --- Parse args ---while [[ $# -gt 0 ]]; docase "$1" in@@ -39,6 +48,8 @@ if [[ -z "${NAME}" ]]; thenexit 1fi+validate_backup_name "${NAME}"+SRC="${BACKUPS_DIR}/${NAME}"# --- Validate backup ---diff --git a/scripts/vm_switch.sh b/scripts/vm_switch.shindex 73228324..37b5335e 100755--- a/scripts/vm_switch.sh+++ b/scripts/vm_switch.sh@@ -13,6 +13,15 @@ BACKUPS_DIR="${BACKUPS_DIR:-vm.backups}"NAME="${NAME:-}"BACKUP_INCLUDE_IPSW="${BACKUP_INCLUDE_IPSW:-0}"+validate_backup_name() {+ local name="$1"+ local label="${2:-NAME}"+ if [[ "$name" == */* || "$name" == .* ]]; then+ echo "ERROR: ${label} must be a simple identifier (no slashes or leading dots)."+ exit 1+ fi+}+# --- Parse args ---while [[ $# -gt 0 ]]; docase "$1" in@@ -41,6 +50,8 @@ if [[ -z "${NAME}" ]]; thenexit 1fi+validate_backup_name "${NAME}"+TARGET="${BACKUPS_DIR}/${NAME}"if [[ ! -d "${TARGET}" || ! -f "${TARGET}/config.plist" ]]; then@@ -81,6 +92,8 @@ if [[ -d "${VM_DIR}" && -f "${VM_DIR}/config.plist" ]]; thenfifi+ validate_backup_name "${CURRENT}" "Current VM name"+if [[ "${CURRENT}" == "${NAME}" ]]; thenecho "'${NAME}' is already the active VM."exit 0