aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2024-04-02 12:19:09 +0200
committersonartech <sonartech@sonarsource.com>2024-04-03 20:02:40 +0000
commitdda2bcce921549b20d7005e380dcc1bd5cdd6464 (patch)
treebc7649b10d7d5c38c3a617c9ef3630d71b43b8c4 /server/sonar-process/src
parent369eb731d47e5d6e2a9016f0d6db6f3c272b1c18 (diff)
downloadsonarqube-dda2bcce921549b20d7005e380dcc1bd5cdd6464.tar.gz
sonarqube-dda2bcce921549b20d7005e380dcc1bd5cdd6464.zip
SONAR-21971 Fix isLocal when multiple loopback adresses
On my Ubuntu box, the hosts file contains: $ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 PC-L00XX And InetAddress.getLocalHost() returns 127.0.1.1, so the test isLocal_returns_true_on_localhost_address_or_host was failing
Diffstat (limited to 'server/sonar-process/src')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java
index cc020e16dfc..0a9765718f6 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java
@@ -124,7 +124,11 @@ public class NetworkUtilsImpl implements NetworkUtils {
try {
Optional<InetAddress> inetAddress = toInetAddress(hostOrAddress);
if (inetAddress.isPresent()) {
- return NetworkInterface.getByInetAddress(inetAddress.get()) != null;
+ var addr = inetAddress.get();
+ if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) {
+ return true;
+ }
+ return NetworkInterface.getByInetAddress(addr) != null;
}
return false;
} catch (SocketException e) {