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>
This commit is contained in:
Rohit Yadav 2019-06-26 23:18:20 +05:30 committed by GitHub
parent 6784cc516b
commit 2c3c88e209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 9 deletions

View File

@ -55,18 +55,16 @@ public class ConsoleProxyInfo {
private String formatProxyAddress(String consoleProxyUrlDomain, String proxyIpAddress) {
StringBuffer sb = new StringBuffer();
// Domain in format *.example.com, proxy IP is 1.2.3.4 --> 1-2-3-4.example.com
if (consoleProxyUrlDomain.startsWith("*")) {
if (StringUtils.isBlank(consoleProxyUrlDomain)) {
// Blank config, we use the proxy IP
sb.append(proxyIpAddress);
} else if (consoleProxyUrlDomain.startsWith("*")) {
// Domain in format *.example.com, proxy IP is 1.2.3.4 --> 1-2-3-4.example.com
sb.append(proxyIpAddress.replaceAll("\\.", "-"));
sb.append(consoleProxyUrlDomain.substring(1)); // skip the *
// Otherwise we assume a valid domain if config not blank
} else if (StringUtils.isNotBlank(consoleProxyUrlDomain)) {
sb.append(consoleProxyUrlDomain);
// Blank config, we use the proxy IP
} else {
sb.append(proxyIpAddress);
// Otherwise we assume a valid domain if config not blank
sb.append(consoleProxyUrlDomain);
}
return sb.toString();
}