Skip to content

Commit 2482a50

Browse files
author
Alex Menkov
committed
8326898: NSK tests should listen on loopback addresses only
Reviewed-by: sspitsyn, cjplummer, dholmes, lmesnik
1 parent e6a8fdd commit 2482a50

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

test/hotspot/jtreg/vmTestbase/nsk/jdi/AttachingConnector/attach/attach004/attach004t.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 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
@@ -102,7 +102,7 @@ public static void main(String args[]) throws InterruptedException {
102102
SocketIOPipe pipe = null;
103103
try {
104104
int portNumber = readPortNumber(log);
105-
pipe = SocketIOPipe.createClientIOPipe(log, "localhost", portNumber, 0);
105+
pipe = SocketIOPipe.createClientIOPipe(log, portNumber, 0);
106106
log.display("Send message to debugger: " + attach004.messageOK);
107107
pipe.println(attach004.messageOK);
108108

test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 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
@@ -54,7 +54,7 @@ protected void targetApplicationActions() {
5454
}
5555

5656
public void runTargetApplication() {
57-
pipe = SocketIOPipe.createClientIOPipe(log, "localhost", argParser.getPort(), 0);
57+
pipe = SocketIOPipe.createClientIOPipe(log, argParser.getPort(), 0);
5858
log.display("Sending signal '" + AODTestRunner.SIGNAL_READY_FOR_ATTACH + "'");
5959
pipe.println(AODTestRunner.SIGNAL_READY_FOR_ATTACH);
6060

test/hotspot/jtreg/vmTestbase/nsk/share/aod/TargetApplicationWaitingAgents.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 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
@@ -341,7 +341,7 @@ public final void runTargetApplication(String[] args) {
341341
/*
342342
* When target application initialized send signal to AODTestRunner
343343
*/
344-
pipe = SocketIOPipe.createClientIOPipe(log, "localhost", argParser.getPort(), 0);
344+
pipe = SocketIOPipe.createClientIOPipe(log, argParser.getPort(), 0);
345345
log.display("Sending signal '" + AODTestRunner.SIGNAL_READY_FOR_ATTACH + "'");
346346
pipe.println(AODTestRunner.SIGNAL_READY_FOR_ATTACH);
347347
}

test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeArgumentHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 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
@@ -108,12 +108,12 @@ public DebugeeArgumentHandler(String args[]) {
108108
/**
109109
* Return name of the host where test executes, specified by
110110
* <code>-test.host</code> command line option or
111-
* "<i>localhost</i>" string by default.
111+
* empty string (represents an address of the loopback interface) by default.
112112
*
113113
* @see #setRawArguments(String[])
114114
*/
115115
public String getTestHost() {
116-
return options.getProperty("test.host", "localhost");
116+
return options.getProperty("test.host", "");
117117
}
118118

119119
/**

test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 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
@@ -180,7 +180,7 @@ public void prepareForPipeConnection(DebugeeArgumentHandler argumentHandler) {
180180
try {
181181
pipeServerSocket = new ServerSocket();
182182
pipeServerSocket.setReuseAddress(false);
183-
pipeServerSocket.bind(null);
183+
pipeServerSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
184184

185185
} catch (IOException e) {
186186
e.printStackTrace(getOutStream());

test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 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
@@ -23,6 +23,7 @@
2323
package nsk.share.jpda;
2424

2525
import java.io.IOException;
26+
import java.net.InetAddress;
2627
import java.net.InetSocketAddress;
2728
import java.net.ServerSocket;
2829
import nsk.share.*;
@@ -35,13 +36,13 @@
3536
*
3637
* Server and client objects should be created using special static methods provided by this class,
3738
* for example 'createServerIOPipe(Log log, int port, long timeout)' for server SocketIOPipe
38-
* and 'createClientIOPipe(Log log, String host, int port, long timeout)' for client SocketIOPipe.
39+
* and 'createClientIOPipe(Log log, int port, long timeout)' for client SocketIOPipe.
3940
*
4041
* When SocketIOPipe is created it can be used to send and receive strings using methods 'readln()' and 'println(String s)'.
4142
* TCP/IP connection is established at the first attempt to read or write data.
4243
*
43-
* For example, if client process should send string 'OK' to the server process which is run
44-
* at the host 'SERVER_HOST' following code can be written:
44+
* For example, if client process should send string 'OK' to the server process,
45+
* the following code can be written:
4546
*
4647
* Server side:
4748
*
@@ -53,8 +54,8 @@
5354
*
5455
* Client side:
5556
*
56-
* // initialize SocketIOPipe with given values of server host name and port
57-
* SocketIOPipe pipe = SocketIOPipe.createClientIOPipe(log, 'SERVER_HOST', port, timeoutValue);
57+
* // initialize SocketIOPipe with given port
58+
* SocketIOPipe pipe = SocketIOPipe.createClientIOPipe(log, port, timeoutValue);
5859
*
5960
* String command = "OK";
6061
* // SocketIOPipe tries to create socket and send command to the server
@@ -123,7 +124,7 @@ public static SocketIOPipe createServerIOPipe(Log log, int port, long timeout) {
123124
// then we should retry the bind() a few times.
124125
ss.setReuseAddress(false);
125126
}
126-
ss.bind(new InetSocketAddress(port));
127+
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
127128
pipe.setServerSocket(ss);
128129
} catch (IOException e) {
129130
e.printStackTrace(log.getOutStream());
@@ -143,8 +144,9 @@ public static SocketIOPipe createServerIOPipe(Log log, long timeout) {
143144
/**
144145
* Create attaching SocketIOPipe using given port and timeout
145146
*/
146-
public static SocketIOPipe createClientIOPipe(Log log, String host, int port, long timeout) {
147-
return new SocketIOPipe(log, DEFAULT_PIPE_LOG_PREFIX, host, port, timeout, false);
147+
public static SocketIOPipe createClientIOPipe(Log log, int port, long timeout) {
148+
// use null for host to connect to loopback address
149+
return new SocketIOPipe(log, DEFAULT_PIPE_LOG_PREFIX, null, port, timeout, false);
148150
}
149151

150152
/**

0 commit comments

Comments
 (0)