From dffa262b889a9ffc26206c5a0902f80d7d879060 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Tue, 21 Jan 2025 13:46:29 +0100 Subject: [PATCH] Add input sanity checking --- misc/build.func | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/misc/build.func b/misc/build.func index 90210829..7834135a 100644 --- a/misc/build.func +++ b/misc/build.func @@ -765,23 +765,38 @@ config_file(){ fi if [[ ! -z "$DISK_SIZE" ]]; then - echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE} GB${CL}" + if [[ "$DISK_SIZE" =~ ^-?[0-9]+$ ]]; then + echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE} GB${CL}" + else + msg_error "DISK_SIZE must be an integer" + exit + fi else - msg_error "Disk Size cannot be empty" + msg_error "DISK_SIZE cannot be empty" exit fi if [[ ! -z "$CORE_COUNT" ]]; then - echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}${CORE_COUNT}${CL}" + if [[ "$CORE_COUNT" =~ ^-?[0-9]+$ ]]; then + echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}${CORE_COUNT}${CL}" + else + msg_error "CORE_COUNT must be an integer" + exit + fi else - msg_error "CPU Cores cannot be empty" + msg_error "CORE_COUNT cannot be empty" exit fi if [[ ! -z "$RAM_SIZE" ]]; then - echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE} MiB${CL}" + if [[ "$RAM_SIZE" =~ ^-?[0-9]+$ ]]; then + echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}${RAM_SIZE} MiB${CL}" + else + msg_error "RAM_SIZE must be an integer" + exit + fi else - msg_error "RAM Size cannot be empty" + msg_error "RAM_SIZE cannot be empty" exit fi @@ -864,8 +879,13 @@ config_file(){ if [[ ! -z "$NS" ]]; then - echo -e "${NETWORK}${BOLD}${DGN}DNS Server IP Address: ${BGN}$NS${CL}" - NS="-nameserver=$NS" + if [[ "$NS" =~ $ip_regex ]]; then + echo -e "${NETWORK}${BOLD}${DGN}DNS Server IP Address: ${BGN}$NS${CL}" + NS="-nameserver=$NS" + else + msg_error "Invalid IP Address format for Name Server: ${NS}" + exit + fi else NS="" echo -e "${NETWORK}${BOLD}${DGN}DNS Server IP Address: ${BGN}HOST${CL}" @@ -877,8 +897,13 @@ config_file(){ fi if [[ ! -z "$VLAN" ]]; then - echo -e "${VLANTAG}${BOLD}${DGN}Vlan: ${BGN}$VLAN${CL}" - VLAN=",tag=$VLAN" + if [[ "$VLAN" =~ ^-?[0-9]+$ ]]; then + echo -e "${VLANTAG}${BOLD}${DGN}Vlan: ${BGN}$VLAN${CL}" + VLAN=",tag=$VLAN" + else + msg_error "VLAN must be an integer" + exit + fi fi if [[ ! -z "$TAGS" ]]; then