Skip to content

Commit a9c17a2

Browse files
committedMar 2, 2024
8327108: compiler.lib.ir_framework.shared.TestFrameworkSocket should listen on loopback address only
Reviewed-by: chagedorn, kvn
1 parent 7f02f07 commit a9c17a2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎test/hotspot/jtreg/compiler/lib/ir_framework/shared/TestFrameworkSocket.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,8 @@
2929
import java.io.IOException;
3030
import java.io.InputStreamReader;
3131
import java.io.PrintWriter;
32+
import java.net.InetAddress;
33+
import java.net.InetSocketAddress;
3234
import java.net.ServerSocket;
3335
import java.net.Socket;
3436
import java.util.concurrent.ExecutionException;
@@ -47,7 +49,6 @@ public class TestFrameworkSocket implements AutoCloseable {
4749
private static final int SERVER_PORT = Integer.getInteger(SERVER_PORT_PROPERTY, -1);
4850

4951
private static final boolean REPRODUCE = Boolean.getBoolean("Reproduce");
50-
private static final String HOSTNAME = null;
5152
private static Socket clientSocket = null;
5253
private static PrintWriter clientWriter = null;
5354

@@ -58,7 +59,8 @@ public class TestFrameworkSocket implements AutoCloseable {
5859

5960
public TestFrameworkSocket() {
6061
try {
61-
serverSocket = new ServerSocket(0);
62+
serverSocket = new ServerSocket();
63+
serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
6264
} catch (IOException e) {
6365
throw new TestFrameworkException("Failed to create TestFramework server socket", e);
6466
}
@@ -132,7 +134,7 @@ public static void write(String msg, String tag, boolean stdout) {
132134
try {
133135
// Keep the client socket open until the test VM terminates (calls closeClientSocket before exiting main()).
134136
if (clientSocket == null) {
135-
clientSocket = new Socket(HOSTNAME, SERVER_PORT);
137+
clientSocket = new Socket(InetAddress.getLoopbackAddress(), SERVER_PORT);
136138
clientWriter = new PrintWriter(clientSocket.getOutputStream(), true);
137139
}
138140
if (stdout) {

0 commit comments

Comments
 (0)
Please sign in to comment.