Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
1f092314
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1f092314
编写于
7月 22, 2013
作者:
M
mchung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8017196: Ensure Proxies are handled appropriately
Reviewed-by: dfuchs, jrose, jdn, ahgross, chegar
上级
bf47e2a1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
88 addition
and
13 deletion
+88
-13
src/share/classes/java/lang/invoke/MethodHandles.java
src/share/classes/java/lang/invoke/MethodHandles.java
+12
-3
src/share/classes/java/lang/reflect/Proxy.java
src/share/classes/java/lang/reflect/Proxy.java
+28
-10
src/share/classes/sun/reflect/misc/ReflectUtil.java
src/share/classes/sun/reflect/misc/ReflectUtil.java
+48
-0
未找到文件。
src/share/classes/java/lang/invoke/MethodHandles.java
浏览文件 @
1f092314
...
...
@@ -433,7 +433,7 @@ public class MethodHandles {
Lookup
(
Class
<?>
lookupClass
)
{
this
(
lookupClass
,
ALL_MODES
);
// make sure we haven't accidentally picked up a privileged class:
checkUnprivilegedlookupClass
(
lookupClass
);
checkUnprivilegedlookupClass
(
lookupClass
,
ALL_MODES
);
}
private
Lookup
(
Class
<?>
lookupClass
,
int
allowedModes
)
{
...
...
@@ -487,7 +487,7 @@ public class MethodHandles {
// No permissions.
newModes
=
0
;
}
checkUnprivilegedlookupClass
(
requestedLookupClass
);
checkUnprivilegedlookupClass
(
requestedLookupClass
,
newModes
);
return
new
Lookup
(
requestedLookupClass
,
newModes
);
}
...
...
@@ -503,10 +503,19 @@ public class MethodHandles {
/** Package-private version of lookup which is trusted. */
static
final
Lookup
IMPL_LOOKUP
=
new
Lookup
(
Object
.
class
,
TRUSTED
);
private
static
void
checkUnprivilegedlookupClass
(
Class
<?>
lookupClass
)
{
private
static
void
checkUnprivilegedlookupClass
(
Class
<?>
lookupClass
,
int
allowedModes
)
{
String
name
=
lookupClass
.
getName
();
if
(
name
.
startsWith
(
"java.lang.invoke."
))
throw
newIllegalArgumentException
(
"illegal lookupClass: "
+
lookupClass
);
// For caller-sensitive MethodHandles.lookup()
// disallow lookup more restricted packages
if
(
allowedModes
==
ALL_MODES
&&
lookupClass
.
getClassLoader
()
==
null
)
{
if
(
name
.
startsWith
(
"java."
)
||
(
name
.
startsWith
(
"sun."
)
&&
!
name
.
startsWith
(
"sun.invoke."
)))
{
throw
newIllegalArgumentException
(
"illegal lookupClass: "
+
lookupClass
);
}
}
}
/**
...
...
src/share/classes/java/lang/reflect/Proxy.java
浏览文件 @
1f092314
...
...
@@ -347,11 +347,11 @@ public class Proxy implements java.io.Serializable {
* s.checkPermission} with
* {@code RuntimePermission("getClassLoader")} permission
* denies access.</li>
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* <li> for each proxy interface, {@code intf},
* the caller's class loader is not the same as or an
* ancestor of the class loader for {@code intf} and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to any one of the
* given proxy interfaces.</li>
* s.checkPackageAccess()} denies access to {@code intf}.</li>
* </ul>
* @throws NullPointerException if the {@code interfaces} array
...
...
@@ -680,11 +680,11 @@ public class Proxy implements java.io.Serializable {
* s.checkPermission} with
* {@code RuntimePermission("getClassLoader")} permission
* denies access;</li>
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* <li> for each proxy interface, {@code intf},
* the caller's class loader is not the same as or an
* ancestor of the class loader for {@code intf} and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to any one of the
* given proxy interfaces.</li>
* s.checkPackageAccess()} denies access to {@code intf};</li>
* <li> any of the given proxy interfaces is non-public and the
* caller class is not in the same {@linkplain Package runtime package}
* as the non-public interface and the invocation of
...
...
@@ -795,7 +795,14 @@ public class Proxy implements java.io.Serializable {
* @return the invocation handler for the proxy instance
* @throws IllegalArgumentException if the argument is not a
* proxy instance
* @throws SecurityException if a security manager, <em>s</em>, is present
* and the caller's class loader is not the same as or an
* ancestor of the class loader for the invocation handler
* and invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the invocation
* handler's class.
*/
@CallerSensitive
public
static
InvocationHandler
getInvocationHandler
(
Object
proxy
)
throws
IllegalArgumentException
{
...
...
@@ -806,8 +813,19 @@ public class Proxy implements java.io.Serializable {
throw
new
IllegalArgumentException
(
"not a proxy instance"
);
}
Proxy
p
=
(
Proxy
)
proxy
;
return
p
.
h
;
final
Proxy
p
=
(
Proxy
)
proxy
;
final
InvocationHandler
ih
=
p
.
h
;
if
(
System
.
getSecurityManager
()
!=
null
)
{
Class
<?>
ihClass
=
ih
.
getClass
();
Class
<?>
caller
=
Reflection
.
getCallerClass
();
if
(
ReflectUtil
.
needsPackageAccessCheck
(
caller
.
getClassLoader
(),
ihClass
.
getClassLoader
()))
{
ReflectUtil
.
checkPackageAccess
(
ihClass
);
}
}
return
ih
;
}
private
static
native
Class
<?>
defineClass0
(
ClassLoader
loader
,
String
name
,
...
...
src/share/classes/sun/reflect/misc/ReflectUtil.java
浏览文件 @
1f092314
...
...
@@ -26,8 +26,10 @@
package
sun.reflect.misc
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Modifier
;
import
java.lang.reflect.Proxy
;
import
java.util.Arrays
;
import
sun.reflect.Reflection
;
public
final
class
ReflectUtil
{
...
...
@@ -250,4 +252,50 @@ public final class ReflectUtil {
String
pkg
=
(
i
!=
-
1
)
?
name
.
substring
(
0
,
i
)
:
""
;
return
Proxy
.
isProxyClass
(
cls
)
&&
!
pkg
.
equals
(
PROXY_PACKAGE
);
}
/**
* Check if the given method is a method declared in the proxy interface
* implemented by the given proxy instance.
*
* @param proxy a proxy instance
* @param method an interface method dispatched to a InvocationHandler
*
* @throws IllegalArgumentException if the given proxy or method is invalid.
*/
public
static
void
checkProxyMethod
(
Object
proxy
,
Method
method
)
{
// check if it is a valid proxy instance
if
(
proxy
==
null
||
!
Proxy
.
isProxyClass
(
proxy
.
getClass
()))
{
throw
new
IllegalArgumentException
(
"Not a Proxy instance"
);
}
if
(
Modifier
.
isStatic
(
method
.
getModifiers
()))
{
throw
new
IllegalArgumentException
(
"Can't handle static method"
);
}
Class
<?>
c
=
method
.
getDeclaringClass
();
if
(
c
==
Object
.
class
)
{
String
name
=
method
.
getName
();
if
(
name
.
equals
(
"hashCode"
)
||
name
.
equals
(
"equals"
)
||
name
.
equals
(
"toString"
))
{
return
;
}
}
if
(
isSuperInterface
(
proxy
.
getClass
(),
c
))
{
return
;
}
// disallow any method not declared in one of the proxy intefaces
throw
new
IllegalArgumentException
(
"Can't handle: "
+
method
);
}
private
static
boolean
isSuperInterface
(
Class
<?>
c
,
Class
<?>
intf
)
{
for
(
Class
<?>
i
:
c
.
getInterfaces
())
{
if
(
i
==
intf
)
{
return
true
;
}
if
(
isSuperInterface
(
i
,
intf
))
{
return
true
;
}
}
return
false
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录