Skip to content

Commit 2c3c88e

Browse files
authored
console-proxy: fix potential NPE condition (#3419)
When checking if the console proxy URL domain starts with *, the code does not check if the provided string is null. When domain is not configured the IP address should be used. Fixes #3164 Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 6784cc5 commit 2c3c88e

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

core/src/main/java/com/cloud/info/ConsoleProxyInfo.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,16 @@ public ConsoleProxyInfo(boolean sslEnabled, String proxyIpAddress, int port, int
5555

5656
private String formatProxyAddress(String consoleProxyUrlDomain, String proxyIpAddress) {
5757
StringBuffer sb = new StringBuffer();
58-
// Domain in format *.example.com, proxy IP is 1.2.3.4 --> 1-2-3-4.example.com
59-
if (consoleProxyUrlDomain.startsWith("*")) {
58+
if (StringUtils.isBlank(consoleProxyUrlDomain)) {
59+
// Blank config, we use the proxy IP
60+
sb.append(proxyIpAddress);
61+
} else if (consoleProxyUrlDomain.startsWith("*")) {
62+
// Domain in format *.example.com, proxy IP is 1.2.3.4 --> 1-2-3-4.example.com
6063
sb.append(proxyIpAddress.replaceAll("\\.", "-"));
6164
sb.append(consoleProxyUrlDomain.substring(1)); // skip the *
62-
63-
// Otherwise we assume a valid domain if config not blank
64-
} else if (StringUtils.isNotBlank(consoleProxyUrlDomain)) {
65-
sb.append(consoleProxyUrlDomain);
66-
67-
// Blank config, we use the proxy IP
6865
} else {
69-
sb.append(proxyIpAddress);
66+
// Otherwise we assume a valid domain if config not blank
67+
sb.append(consoleProxyUrlDomain);
7068
}
7169
return sb.toString();
7270
}

0 commit comments

Comments
 (0)