Merge
This commit is contained in:
commit
6029b480b7
@ -31,7 +31,7 @@ import javax.management.DynamicMBean;
|
||||
/**
|
||||
* Management interface for the diagnostic commands for the HotSpot Virtual Machine.
|
||||
*
|
||||
* <p>The {code DiagnosticCommandMBean} is registered to the
|
||||
* <p>The {@code DiagnosticCommandMBean} is registered to the
|
||||
* {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
|
||||
* platform MBeanServer} as are other platform MBeans.
|
||||
*
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -184,15 +185,26 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
|
||||
res = errno;
|
||||
}
|
||||
|
||||
/* release p here before we throw an I/O exception */
|
||||
if (isCopy) {
|
||||
JNU_ReleaseStringPlatformChars(env, path, p);
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
if ( (sb.st_uid != uid) || (sb.st_gid != gid) ||
|
||||
((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) ) {
|
||||
JNU_ThrowIOException(env, "well-known file is not secure");
|
||||
char msg[100];
|
||||
jboolean isError = JNI_FALSE;
|
||||
if (sb.st_uid != uid) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file should be owned by the current user (which is %d) but is owned by %d", uid, sb.st_uid);
|
||||
isError = JNI_TRUE;
|
||||
} else if (sb.st_gid != gid) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file's group should be the current group (which is %d) but the group is %d", gid, sb.st_gid);
|
||||
isError = JNI_TRUE;
|
||||
} else if ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file should only be readable and writable by the owner but has 0%03o access", sb.st_mode & 0777);
|
||||
isError = JNI_TRUE;
|
||||
}
|
||||
if (isError) {
|
||||
char buf[256];
|
||||
jio_snprintf(buf, sizeof(buf)-1, "well-known file %s is not secure: %s", p, msg);
|
||||
JNU_ThrowIOException(env, buf);
|
||||
}
|
||||
} else {
|
||||
char* msg = strdup(strerror(res));
|
||||
@ -201,6 +213,10 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
|
||||
free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCopy) {
|
||||
JNU_ReleaseStringPlatformChars(env, path, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -369,15 +370,26 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
|
||||
res = errno;
|
||||
}
|
||||
|
||||
/* release p here before we throw an I/O exception */
|
||||
if (isCopy) {
|
||||
JNU_ReleaseStringPlatformChars(env, path, p);
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
if ( (sb.st_uid != uid) || (sb.st_gid != gid) ||
|
||||
((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) ) {
|
||||
JNU_ThrowIOException(env, "well-known file is not secure");
|
||||
char msg[100];
|
||||
jboolean isError = JNI_FALSE;
|
||||
if (sb.st_uid != uid) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file should be owned by the current user (which is %d) but is owned by %d", uid, sb.st_uid);
|
||||
isError = JNI_TRUE;
|
||||
} else if (sb.st_gid != gid) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file's group should be the current group (which is %d) but the group is %d", gid, sb.st_gid);
|
||||
isError = JNI_TRUE;
|
||||
} else if ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file should only be readable and writable by the owner but has 0%03o access", sb.st_mode & 0777);
|
||||
isError = JNI_TRUE;
|
||||
}
|
||||
if (isError) {
|
||||
char buf[256];
|
||||
jio_snprintf(buf, sizeof(buf)-1, "well-known file %s is not secure: %s", p, msg);
|
||||
JNU_ThrowIOException(env, buf);
|
||||
}
|
||||
} else {
|
||||
char* msg = strdup(strerror(res));
|
||||
@ -386,6 +398,10 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
|
||||
free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCopy) {
|
||||
JNU_ReleaseStringPlatformChars(env, path, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -151,15 +152,26 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
|
||||
res = errno;
|
||||
}
|
||||
|
||||
/* release p here before we throw an I/O exception */
|
||||
if (isCopy) {
|
||||
JNU_ReleaseStringPlatformChars(env, path, p);
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
if ( (sb.st_uid != uid) || (sb.st_gid != gid) ||
|
||||
((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) ) {
|
||||
JNU_ThrowIOException(env, "well-known file is not secure");
|
||||
char msg[100];
|
||||
jboolean isError = JNI_FALSE;
|
||||
if (sb.st_uid != uid) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file should be owned by the current user (which is %d) but is owned by %d", uid, sb.st_uid);
|
||||
isError = JNI_TRUE;
|
||||
} else if (sb.st_gid != gid) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file's group should be the current group (which is %d) but the group is %d", gid, sb.st_gid);
|
||||
isError = JNI_TRUE;
|
||||
} else if ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file should only be readable and writable by the owner but has 0%03o access", sb.st_mode & 0777);
|
||||
isError = JNI_TRUE;
|
||||
}
|
||||
if (isError) {
|
||||
char buf[256];
|
||||
jio_snprintf(buf, sizeof(buf)-1, "well-known file %s is not secure: %s", p, msg);
|
||||
JNU_ThrowIOException(env, buf);
|
||||
}
|
||||
} else {
|
||||
char* msg = strdup(strerror(res));
|
||||
@ -168,6 +180,10 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
|
||||
free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCopy) {
|
||||
JNU_ReleaseStringPlatformChars(env, path, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
|
||||
#include "sun_tools_attach_VirtualMachineImpl.h"
|
||||
|
||||
@ -112,15 +113,26 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
|
||||
res = errno;
|
||||
}
|
||||
|
||||
/* release p here before we throw an I/O exception */
|
||||
if (isCopy) {
|
||||
JNU_ReleaseStringPlatformChars(env, path, p);
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
if ( (sb.st_uid != uid) || (sb.st_gid != gid) ||
|
||||
((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) ) {
|
||||
JNU_ThrowIOException(env, "well-known file is not secure");
|
||||
char msg[100];
|
||||
jboolean isError = JNI_FALSE;
|
||||
if (sb.st_uid != uid) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file should be owned by the current user (which is %d) but is owned by %d", uid, sb.st_uid);
|
||||
isError = JNI_TRUE;
|
||||
} else if (sb.st_gid != gid) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file's group should be the current group (which is %d) but the group is %d", gid, sb.st_gid);
|
||||
isError = JNI_TRUE;
|
||||
} else if ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) {
|
||||
jio_snprintf(msg, sizeof(msg)-1,
|
||||
"file should only be readable and writable by the owner but has 0%03o access", sb.st_mode & 0777);
|
||||
isError = JNI_TRUE;
|
||||
}
|
||||
if (isError) {
|
||||
char buf[256];
|
||||
jio_snprintf(buf, sizeof(buf)-1, "well-known file %s is not secure: %s", p, msg);
|
||||
JNU_ThrowIOException(env, buf);
|
||||
}
|
||||
} else {
|
||||
char* msg = strdup(strerror(res));
|
||||
@ -129,6 +141,10 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
|
||||
free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCopy) {
|
||||
JNU_ReleaseStringPlatformChars(env, path, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,9 +283,6 @@ tools/launcher/FXLauncherTest.java linux-all
|
||||
|
||||
# jdk_jdi
|
||||
|
||||
# 6983531
|
||||
com/sun/jdi/BadHandshakeTest.java linux-all,windows-all
|
||||
|
||||
# 8004127
|
||||
com/sun/jdi/RedefineImplementor.sh generic-all
|
||||
|
||||
|
@ -21,22 +21,15 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 6306165 6432567
|
||||
* @summary Check that a bad handshake doesn't cause a debuggee to abort
|
||||
* @library /lib/testlibrary
|
||||
*
|
||||
* @build jdk.testlibrary.* VMConnection BadHandshakeTest Exit0
|
||||
* @run driver BadHandshakeTest
|
||||
*
|
||||
*/
|
||||
import java.net.Socket;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import com.sun.jdi.Bootstrap;
|
||||
import com.sun.jdi.VirtualMachine;
|
||||
import com.sun.jdi.event.*;
|
||||
import com.sun.jdi.connect.Connector;
|
||||
import com.sun.jdi.connect.AttachingConnector;
|
||||
import com.sun.jdi.connect.Connector.Argument;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
@ -46,13 +39,22 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import jdk.testlibrary.Utils;
|
||||
import jdk.testlibrary.ProcessTools;
|
||||
|
||||
/* @test
|
||||
* @bug 6306165 6432567
|
||||
* @summary Check that a bad handshake doesn't cause a debuggee to abort
|
||||
* @library /lib/testlibrary
|
||||
*
|
||||
* @build jdk.testlibrary.* VMConnection BadHandshakeTest Exit0
|
||||
* @run driver BadHandshakeTest
|
||||
*/
|
||||
public class BadHandshakeTest {
|
||||
|
||||
/*
|
||||
* Find a connector by name
|
||||
*/
|
||||
private static Connector findConnector(String name) {
|
||||
List connectors = Bootstrap.virtualMachineManager().allConnectors();
|
||||
Iterator iter = connectors.iterator();
|
||||
List<Connector> connectors = Bootstrap.virtualMachineManager().allConnectors();
|
||||
Iterator<Connector> iter = connectors.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Connector connector = (Connector)iter.next();
|
||||
if (connector.name().equals(name)) {
|
||||
@ -65,7 +67,7 @@ public class BadHandshakeTest {
|
||||
/*
|
||||
* Launch a server debuggee with the given address
|
||||
*/
|
||||
private static Process launch(String address, String class_name) throws Exception {
|
||||
private static LaunchResult launch(String address, String class_name) throws Exception {
|
||||
String[] args = VMConnection.insertDebuggeeVMOptions(new String[] {
|
||||
"-agentlib:jdwp=transport=dt_socket" +
|
||||
",server=y" + ",suspend=y" + ",address=" + address,
|
||||
@ -75,6 +77,7 @@ public class BadHandshakeTest {
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
|
||||
|
||||
final AtomicBoolean success = new AtomicBoolean();
|
||||
final AtomicBoolean bindFailed = new AtomicBoolean();
|
||||
Process p = ProcessTools.startProcess(
|
||||
class_name,
|
||||
pb,
|
||||
@ -83,13 +86,17 @@ public class BadHandshakeTest {
|
||||
// Listening for transport dt_socket at address: xxxxx
|
||||
// which shows the debuggee is ready to accept connections.
|
||||
success.set(line.contains("Listening for transport dt_socket at address:"));
|
||||
// If the first line contains 'Address already in use'
|
||||
// that means the debuggee has failed to start due to busy port
|
||||
bindFailed.set(line.contains("Address already in use"));
|
||||
return true;
|
||||
},
|
||||
Integer.MAX_VALUE,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
|
||||
return success.get() ? p : null;
|
||||
return new LaunchResult(success.get() ? p : null,
|
||||
bindFailed.get());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -99,14 +106,20 @@ public class BadHandshakeTest {
|
||||
* - verify we saw no error
|
||||
*/
|
||||
public static void main(String args[]) throws Exception {
|
||||
int port = Utils.getFreePort();
|
||||
|
||||
String address = String.valueOf(port);
|
||||
|
||||
// launch the server debuggee
|
||||
Process process = launch(address, "Exit0");
|
||||
if (process == null) {
|
||||
throw new RuntimeException("Unable to start debugee");
|
||||
// Launch the server debuggee
|
||||
int port = 0;
|
||||
Process process = null;
|
||||
while (process == null) {
|
||||
port = Utils.getFreePort();
|
||||
String address = String.valueOf(port);
|
||||
LaunchResult launchResult = launch(address, "Exit0");
|
||||
process = launchResult.getProcess();
|
||||
if (launchResult.isBindFailed()) {
|
||||
System.out.println("Port " + port + " already in use. Trying to restart debuggee with a new one...");
|
||||
Thread.sleep(100);
|
||||
} else if (process == null ) {
|
||||
throw new RuntimeException("Unable to start debugee");
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to the debuggee and handshake with garbage
|
||||
@ -119,9 +132,9 @@ public class BadHandshakeTest {
|
||||
s.getOutputStream().write("JDWP-".getBytes("UTF-8"));
|
||||
|
||||
|
||||
// attach to server debuggee and resume it so it can exit
|
||||
// Attach to server debuggee and resume it so it can exit
|
||||
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
|
||||
Map conn_args = conn.defaultArguments();
|
||||
Map<String, Argument> conn_args = conn.defaultArguments();
|
||||
Connector.IntegerArgument port_arg =
|
||||
(Connector.IntegerArgument)conn_args.get("port");
|
||||
port_arg.setValue(port);
|
||||
@ -143,4 +156,24 @@ public class BadHandshakeTest {
|
||||
process.waitFor();
|
||||
}
|
||||
|
||||
private static class LaunchResult {
|
||||
|
||||
private final Process p;
|
||||
private final boolean bindFailed;
|
||||
|
||||
public LaunchResult(Process p, boolean bindFailed) {
|
||||
this.p = p;
|
||||
this.bindFailed = bindFailed;
|
||||
}
|
||||
|
||||
public Process getProcess() {
|
||||
return p;
|
||||
}
|
||||
|
||||
public boolean isBindFailed() {
|
||||
return bindFailed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,8 @@
|
||||
package jdk.testlibrary;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
@ -34,6 +36,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@ -188,8 +191,8 @@ public final class ProcessTools {
|
||||
} else {
|
||||
latch.countDown();
|
||||
}
|
||||
Future<Void> stdoutTask = stdout.process();
|
||||
Future<Void> stderrTask = stderr.process();
|
||||
final Future<Void> stdoutTask = stdout.process();
|
||||
final Future<Void> stderrTask = stderr.process();
|
||||
|
||||
try {
|
||||
if (timeout > -1) {
|
||||
@ -216,7 +219,7 @@ public final class ProcessTools {
|
||||
throw e;
|
||||
}
|
||||
|
||||
return p;
|
||||
return new ProcessImpl(p, stdoutTask, stderrTask);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -436,4 +439,84 @@ public final class ProcessTools {
|
||||
System.out.println(analyzer.getOutput());
|
||||
return analyzer;
|
||||
}
|
||||
|
||||
private static class ProcessImpl extends Process {
|
||||
|
||||
private final Process p;
|
||||
private final Future<Void> stdoutTask;
|
||||
private final Future<Void> stderrTask;
|
||||
|
||||
public ProcessImpl(Process p, Future<Void> stdoutTask, Future<Void> stderrTask) {
|
||||
this.p = p;
|
||||
this.stdoutTask = stdoutTask;
|
||||
this.stderrTask = stderrTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() {
|
||||
return p.getOutputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return p.getInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getErrorStream() {
|
||||
return p.getErrorStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int waitFor() throws InterruptedException {
|
||||
int rslt = p.waitFor();
|
||||
waitForStreams();
|
||||
return rslt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int exitValue() {
|
||||
return p.exitValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
p.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPid() {
|
||||
return p.getPid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
return p.isAlive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Process destroyForcibly() {
|
||||
return p.destroyForcibly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException {
|
||||
boolean rslt = p.waitFor(timeout, unit);
|
||||
if (rslt) {
|
||||
waitForStreams();
|
||||
}
|
||||
return rslt;
|
||||
}
|
||||
|
||||
private void waitForStreams() throws InterruptedException {
|
||||
try {
|
||||
stdoutTask.get();
|
||||
} catch (ExecutionException e) {
|
||||
}
|
||||
try {
|
||||
stderrTask.get();
|
||||
} catch (ExecutionException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,6 @@ public class JMXStartStopTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.err.println("*** port = " + port);
|
||||
ports[i] = port;
|
||||
}
|
||||
return ports;
|
||||
|
Loading…
x
Reference in New Issue
Block a user