mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 21:03:08 +00:00
fix: validate both ports before assigning either
Collect web and server port inputs first, then validate both before assigning to global variables. This prevents WEB_PORT from being modified when SERVER_PORT validation subsequently fails. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -535,20 +535,23 @@ check_ports() {
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
[uU]|[uU][sS][eE])
|
[uU]|[uU][sS][eE])
|
||||||
|
# Collect both ports first
|
||||||
read -r -p "Enter web port (default $DEFAULT_WEB_PORT): " input_web
|
read -r -p "Enter web port (default $DEFAULT_WEB_PORT): " input_web
|
||||||
input_web=${input_web:-$DEFAULT_WEB_PORT}
|
input_web=${input_web:-$DEFAULT_WEB_PORT}
|
||||||
|
read -r -p "Enter server port (default $DEFAULT_SERVER_PORT): " input_server
|
||||||
|
input_server=${input_server:-$DEFAULT_SERVER_PORT}
|
||||||
|
|
||||||
|
# Validate both before assigning either
|
||||||
if ! validate_port "$input_web" "Web port"; then
|
if ! validate_port "$input_web" "Web port"; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
WEB_PORT=$input_web
|
|
||||||
|
|
||||||
read -r -p "Enter server port (default $DEFAULT_SERVER_PORT): " input_server
|
|
||||||
input_server=${input_server:-$DEFAULT_SERVER_PORT}
|
|
||||||
if ! validate_port "$input_server" "Server port"; then
|
if ! validate_port "$input_server" "Server port"; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
SERVER_PORT=$input_server
|
|
||||||
|
|
||||||
|
# Assign atomically after both validated
|
||||||
|
WEB_PORT=$input_web
|
||||||
|
SERVER_PORT=$input_server
|
||||||
echo "${C_GREEN}Using ports: Web=$WEB_PORT, Server=$SERVER_PORT${RESET}"
|
echo "${C_GREEN}Using ports: Web=$WEB_PORT, Server=$SERVER_PORT${RESET}"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
@@ -836,22 +839,25 @@ resolve_port_conflicts() {
|
|||||||
[uU]|[uU][sS][eE])
|
[uU]|[uU][sS][eE])
|
||||||
echo ""
|
echo ""
|
||||||
local input_pad=$(( (TERM_COLS - 40) / 2 ))
|
local input_pad=$(( (TERM_COLS - 40) / 2 ))
|
||||||
|
# Collect both ports first
|
||||||
printf "%${input_pad}s" ""
|
printf "%${input_pad}s" ""
|
||||||
read -r -p "Enter web port (default $DEFAULT_WEB_PORT): " input_web
|
read -r -p "Enter web port (default $DEFAULT_WEB_PORT): " input_web
|
||||||
input_web=${input_web:-$DEFAULT_WEB_PORT}
|
input_web=${input_web:-$DEFAULT_WEB_PORT}
|
||||||
if ! validate_port "$input_web" "Web port"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
WEB_PORT=$input_web
|
|
||||||
|
|
||||||
printf "%${input_pad}s" ""
|
printf "%${input_pad}s" ""
|
||||||
read -r -p "Enter server port (default $DEFAULT_SERVER_PORT): " input_server
|
read -r -p "Enter server port (default $DEFAULT_SERVER_PORT): " input_server
|
||||||
input_server=${input_server:-$DEFAULT_SERVER_PORT}
|
input_server=${input_server:-$DEFAULT_SERVER_PORT}
|
||||||
|
|
||||||
|
# Validate both before assigning either
|
||||||
|
if ! validate_port "$input_web" "Web port"; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
if ! validate_port "$input_server" "Server port"; then
|
if ! validate_port "$input_server" "Server port"; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
SERVER_PORT=$input_server
|
|
||||||
|
|
||||||
|
# Assign atomically after both validated
|
||||||
|
WEB_PORT=$input_web
|
||||||
|
SERVER_PORT=$input_server
|
||||||
center_print "Using ports: Web=$WEB_PORT, Server=$SERVER_PORT" "$C_GREEN"
|
center_print "Using ports: Web=$WEB_PORT, Server=$SERVER_PORT" "$C_GREEN"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user