Skip to content

8333680: com/sun/tools/attach/BasicTests.java fails with "SocketException: Permission denied: connect" #3538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/jdk/com/sun/tools/attach/Agent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,6 +28,7 @@
* the given port.
*/
import java.net.Socket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.io.IOException;

Expand All @@ -38,7 +39,7 @@ public static void agentmain(String args) throws IOException {
int port = Integer.parseInt(args);
System.out.println("Agent connecting back to Tool....");
Socket s = new Socket();
s.connect( new InetSocketAddress(port) );
s.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
System.out.println("Agent connected to Tool.");
s.close();
}
Expand Down
8 changes: 6 additions & 2 deletions test/jdk/com/sun/tools/attach/BasicTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;
Expand Down Expand Up @@ -213,7 +215,8 @@ public static void main(String args[]) throws Exception {

System.out.println(" - Test: End-to-end connection with agent");

ServerSocket ss = new ServerSocket(0);
ServerSocket ss = new ServerSocket();
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
int port = ss.getLocalPort();

System.out.println(" - Loading Agent.jar into target VM ...");
Expand All @@ -231,7 +234,8 @@ public static void main(String args[]) throws Exception {

System.out.println(" - Test: End-to-end connection with RedefineAgent");

ServerSocket ss2 = new ServerSocket(0);
ServerSocket ss2 = new ServerSocket();
ss2.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
int port2 = ss2.getLocalPort();

System.out.println(" - Loading RedefineAgent.jar into target VM ...");
Expand Down
5 changes: 3 additions & 2 deletions test/jdk/com/sun/tools/attach/RedefineAgent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,6 +32,7 @@
* 6446941 java.lang.instrument: multiple agent attach fails (first agent chooses capabilities)
*/
import java.net.Socket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -104,7 +105,7 @@ public static void agentmain(String args, Instrumentation inst) throws Exception
int port = Integer.parseInt(args);
System.out.println("RedefineAgent connecting back to Tool....");
Socket s = new Socket();
s.connect( new InetSocketAddress(port) );
s.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
System.out.println("RedefineAgent connected to Tool.");

testRedefine(inst);
Expand Down