From 2854e24e8401cdd38a0e1b9ca2f5d4f22b97f7a4 Mon Sep 17 00:00:00 2001 From: Scott Date: Sun, 18 Jan 2026 13:46:11 -0700 Subject: [PATCH] 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 --- start-automaker.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/start-automaker.sh b/start-automaker.sh index 62adb4a4..ee273348 100755 --- a/start-automaker.sh +++ b/start-automaker.sh @@ -535,20 +535,23 @@ check_ports() { break ;; [uU]|[uU][sS][eE]) + # Collect both ports first read -r -p "Enter web port (default $DEFAULT_WEB_PORT): " input_web 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 continue 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 continue 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}" break ;; @@ -836,22 +839,25 @@ resolve_port_conflicts() { [uU]|[uU][sS][eE]) echo "" local input_pad=$(( (TERM_COLS - 40) / 2 )) + # Collect both ports first printf "%${input_pad}s" "" read -r -p "Enter web port (default $DEFAULT_WEB_PORT): " input_web 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" "" 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 + continue + fi if ! validate_port "$input_server" "Server port"; then continue 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" break ;;