1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# HG changeset patch
# User andrew
# Date 1365784460 -3600
# Node ID e0803f17f824df0bbedf0dd03aa06938389b1b9f
# Parent dfa1c658a62a54dbcfa02e96c51af21a3cc71907
8006435: Improvements in JMX
Summary: Improvements in JMX
Reviewed-by: dfuchs, skoivu
diff --git a/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java b/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java
--- jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java
+++ jdk/src/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, 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
@@ -213,7 +213,6 @@
Object moi = null;
-
// ------------------------------
// ------------------------------
Constructor cons = findConstructor(theClass, null);
@@ -224,6 +223,7 @@
// Instantiate the new object
try {
ReflectUtil.checkPackageAccess(theClass);
+ ReflectUtil.ensureClassAccess(theClass);
moi= cons.newInstance();
} catch (InvocationTargetException e) {
// Wrap the exception.
@@ -270,7 +270,6 @@
checkMBeanPermission(theClass, null, null, "instantiate");
// Instantiate the new object
-
// ------------------------------
// ------------------------------
final Class[] tab;
@@ -301,6 +300,7 @@
}
try {
ReflectUtil.checkPackageAccess(theClass);
+ ReflectUtil.ensureClassAccess(theClass);
moi = cons.newInstance(params);
}
catch (NoSuchMethodError error) {
diff --git a/src/share/classes/sun/reflect/misc/ReflectUtil.java b/src/share/classes/sun/reflect/misc/ReflectUtil.java
--- jdk/src/share/classes/sun/reflect/misc/ReflectUtil.java
+++ jdk/src/share/classes/sun/reflect/misc/ReflectUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, 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
@@ -46,6 +46,14 @@
return cls.newInstance();
}
+ public static void ensureClassAccess(Class clazz)
+ throws IllegalAccessException
+ {
+ int mod = clazz.getModifiers();
+ if ( ! Modifier.isPublic(mod) ){
+ throw new IllegalAccessException("Class is not public and can't be instantiated");
+ }
+ }
/*
* Reflection.ensureMemberAccess is overly-restrictive
* due to a bug. We awkwardly work around it for now.
|