Get a little more protective of user input in qemu

This commit is contained in:
Tianon Gravi 2017-03-22 13:59:30 -07:00
parent e51e8b827f
commit 03bab76008

View File

@ -15,7 +15,7 @@ hostArch="$(uname -m)"
qemuArch="${QEMU_ARCH:-$hostArch}" qemuArch="${QEMU_ARCH:-$hostArch}"
qemu="${QEMU_BIN:-qemu-system-$qemuArch}" qemu="${QEMU_BIN:-qemu-system-$qemuArch}"
qemuArgs=() qemuArgs=()
qemuPorts=( 22 $QEMU_PORTS ) qemuPorts=( 22 ${QEMU_PORTS:-} )
if [ -e /dev/kvm ]; then if [ -e /dev/kvm ]; then
qemuArgs+=( -enable-kvm ) qemuArgs+=( -enable-kvm )
@ -31,7 +31,7 @@ fi
qemuArgs+=( -smp "${QEMU_CPU:-1}" ) qemuArgs+=( -smp "${QEMU_CPU:-1}" )
qemuArgs+=( -m "${QEMU_RAM:-512}" ) qemuArgs+=( -m "${QEMU_RAM:-512}" )
if [ "$QEMU_HDA" ]; then if [ -n "${QEMU_HDA:-}" ]; then
if [ ! -f "$QEMU_HDA" -o ! -s "$QEMU_HDA" ]; then if [ ! -f "$QEMU_HDA" -o ! -s "$QEMU_HDA" ]; then
( (
set -x set -x
@ -43,17 +43,17 @@ if [ "$QEMU_HDA" ]; then
qemuArgs+=( -drive file="$QEMU_HDA",index=0,media=disk,discard=unmap ) qemuArgs+=( -drive file="$QEMU_HDA",index=0,media=disk,discard=unmap )
fi fi
if [ "$QEMU_CDROM" ]; then if [ -n "${QEMU_CDROM:-}" ]; then
qemuArgs+=( -cdrom "$QEMU_CDROM" ) qemuArgs+=( -cdrom "$QEMU_CDROM" )
fi fi
if [ "$QEMU_BOOT" ]; then if [ -n "${QEMU_BOOT:-}" ]; then
qemuArgs+=( -boot "$QEMU_BOOT" ) qemuArgs+=( -boot "$QEMU_BOOT" )
fi fi
netArg='user' netArg='user'
netArg+=",hostname=$(hostname)" netArg+=",hostname=$(hostname)"
if [ "$QEMU_NET_USER_EXTRA" ]; then if [ -n "${QEMU_NET_USER_EXTRA:-}" ]; then
netArg+=",$QEMU_NET_USER_EXTRA" netArg+=",$QEMU_NET_USER_EXTRA"
fi fi
for port in "${qemuPorts[@]}"; do for port in "${qemuPorts[@]}"; do