From cde3d7d35c5fae71e256e37ab651151df6e8d5e7 Mon Sep 17 00:00:00 2001 From: Emmanuel Hugonnet Date: Wed, 28 Feb 2024 13:46:34 +0100 Subject: [PATCH] [WFCORE-6717]: Incorrectly set options on the command line should fail to start a server. * If no value is defined for yaml o git command line options we should fail. Jira: https://issues.redhat.com/browse/WFCORE-6717 Signed-off-by: Emmanuel Hugonnet --- .../main/java/org/jboss/as/server/Main.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/org/jboss/as/server/Main.java b/server/src/main/java/org/jboss/as/server/Main.java index c072e76b014..3f0149c33dc 100644 --- a/server/src/main/java/org/jboss/as/server/Main.java +++ b/server/src/main/java/org/jboss/as/server/Main.java @@ -323,45 +323,48 @@ public static ServerEnvironmentWrapper determineEnvironment(String[] args, Prope // do nothing, just need to filter out as Windows batch scripts cannot filter it out } else if(arg.startsWith(CommandLineConstants.GIT_REPO)) { int idx = arg.indexOf("="); + if (idx == arg.length() - 1) { + return requireValue(arg, productConfig); + } if (idx == -1) { final int next = i + 1; if (next < argsLength) { gitRepository = args[next]; i++; } else { - STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg)); - usage(productConfig); - return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR); + return requireValue(arg, productConfig); } } else { gitRepository = arg.substring(idx + 1); } } else if(arg.startsWith(CommandLineConstants.GIT_AUTH)) { int idx = arg.indexOf("="); + if (idx == arg.length() - 1) { + return requireValue(arg, productConfig); + } if (idx == -1) { final int next = i + 1; if (next < argsLength) { gitAuthConfiguration = args[next]; i++; } else { - STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg)); - usage(productConfig); - return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR); + return requireValue(arg, productConfig); } } else { gitAuthConfiguration = arg.substring(idx + 1); } } else if(arg.startsWith(CommandLineConstants.GIT_BRANCH)) { int idx = arg.indexOf("="); + if (idx == arg.length() - 1) { + return requireValue(arg, productConfig); + } if (idx == -1) { final int next = i + 1; if (next < argsLength) { gitBranch = args[next]; i++; } else { - STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg)); - usage(productConfig); - return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR); + return requireValue(arg, productConfig); } } else { gitBranch = arg.substring(idx + 1); @@ -375,15 +378,16 @@ public static ServerEnvironmentWrapper determineEnvironment(String[] args, Prope } else if(ConfigurationExtensionFactory.isConfigurationExtensionSupported() && ConfigurationExtensionFactory.commandLineContainsArgument(arg)) { int idx = arg.indexOf("="); + if (idx == arg.length() - 1) { + return requireValue(arg, productConfig); + } if (idx == -1) { final int next = i + 1; if (next < argsLength) { supplementalConfiguration = args[next]; i++; } else { - STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg)); - usage(productConfig); - return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR); + return requireValue(arg, productConfig); } } else { supplementalConfiguration = arg.substring(idx + 1); @@ -394,9 +398,7 @@ public static ServerEnvironmentWrapper determineEnvironment(String[] args, Prope return new ServerEnvironmentWrapper (ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR); } } catch (IndexOutOfBoundsException e) { - STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg)); - usage(productConfig); - return new ServerEnvironmentWrapper(ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR); + return requireValue(arg, productConfig); } } @@ -408,6 +410,12 @@ public static ServerEnvironmentWrapper determineEnvironment(String[] args, Prope startGracefully, gitRepository, gitBranch, gitAuthConfiguration, supplementalConfiguration)); } + private static ServerEnvironmentWrapper requireValue(String arg, ProductConfig productConfig) { + STDERR.println(ServerLogger.ROOT_LOGGER.valueExpectedForCommandLineOption(arg)); + usage(productConfig); + return new ServerEnvironmentWrapper(ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR); + } + private static void assertSingleConfig(String serverConfig) { if (serverConfig != null) { throw ServerLogger.ROOT_LOGGER.cannotHaveBothInitialServerConfigAndServerConfig();