From 9cf55808fb17daa9277424ecb5305c2b1516c07e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 12 Jan 2022 10:42:45 -0800 Subject: [PATCH] Ensure run user actually exists Update `launch.script` so that the `run_user` variable is only set when the user actually exists. Prior to this commit, if the jar file was owned by a non-existing user the startup script could fail. Fixes gh-29370 --- .../org/springframework/boot/loader/tools/launch.script | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script index c409a4fd88..ce3115c437 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script @@ -128,6 +128,9 @@ log_file="$LOG_FOLDER/$LOG_FILENAME" # shellcheck disable=SC2012 [[ $(id -u) == "0" ]] && run_user=$(ls -ld "$jarfile" | awk '{print $3}') +# Ensure the user actually exists +id -u "$run_user" &> /dev/null || unset run_user + # Run as user specified in RUN_AS_USER if [[ -n "$RUN_AS_USER" ]]; then if ! [[ "$action" =~ ^(status|run)$ ]]; then