Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
3f2298d8
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看板
提交
3f2298d8
编写于
9月 28, 2010
作者:
S
skoppar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6966692: defaultReadObject can set a field multiple times
Reviewed-by: hawtin
上级
cec0509b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
188 addition
and
9 deletion
+188
-9
src/share/classes/java/io/ObjectStreamClass.java
src/share/classes/java/io/ObjectStreamClass.java
+17
-9
test/java/io/Serializable/6966692/Attack.java
test/java/io/Serializable/6966692/Attack.java
+34
-0
test/java/io/Serializable/6966692/README
test/java/io/Serializable/6966692/README
+23
-0
test/java/io/Serializable/6966692/Test6966692.sh
test/java/io/Serializable/6966692/Test6966692.sh
+79
-0
test/java/io/Serializable/6966692/Victim.java
test/java/io/Serializable/6966692/Victim.java
+35
-0
未找到文件。
src/share/classes/java/io/ObjectStreamClass.java
浏览文件 @
3f2298d8
/*
* Copyright (c) 1996, 20
08
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 20
10
, 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
...
...
@@ -1830,8 +1830,10 @@ public class ObjectStreamClass implements Serializable {
private
final
ObjectStreamField
[]
fields
;
/** number of primitive fields */
private
final
int
numPrimFields
;
/** unsafe field keys */
private
final
long
[]
keys
;
/** unsafe field keys for reading fields - may contain dupes */
private
final
long
[]
readKeys
;
/** unsafe fields keys for writing fields - no dupes */
private
final
long
[]
writeKeys
;
/** field data offsets */
private
final
int
[]
offsets
;
/** field type codes */
...
...
@@ -1849,16 +1851,22 @@ public class ObjectStreamClass implements Serializable {
FieldReflector
(
ObjectStreamField
[]
fields
)
{
this
.
fields
=
fields
;
int
nfields
=
fields
.
length
;
keys
=
new
long
[
nfields
];
readKeys
=
new
long
[
nfields
];
writeKeys
=
new
long
[
nfields
];
offsets
=
new
int
[
nfields
];
typeCodes
=
new
char
[
nfields
];
ArrayList
<
Class
<?>>
typeList
=
new
ArrayList
<
Class
<?>>();
Set
<
Long
>
usedKeys
=
new
HashSet
<
Long
>();
for
(
int
i
=
0
;
i
<
nfields
;
i
++)
{
ObjectStreamField
f
=
fields
[
i
];
Field
rf
=
f
.
getField
();
keys
[
i
]
=
(
rf
!=
null
)
?
long
key
=
(
rf
!=
null
)
?
unsafe
.
objectFieldOffset
(
rf
)
:
Unsafe
.
INVALID_FIELD_OFFSET
;
readKeys
[
i
]
=
key
;
writeKeys
[
i
]
=
usedKeys
.
add
(
key
)
?
key
:
Unsafe
.
INVALID_FIELD_OFFSET
;
offsets
[
i
]
=
f
.
getOffset
();
typeCodes
[
i
]
=
f
.
getTypeCode
();
if
(!
f
.
isPrimitive
())
{
...
...
@@ -1894,7 +1902,7 @@ public class ObjectStreamClass implements Serializable {
* in array should be equal to Unsafe.INVALID_FIELD_OFFSET.
*/
for
(
int
i
=
0
;
i
<
numPrimFields
;
i
++)
{
long
key
=
k
eys
[
i
];
long
key
=
readK
eys
[
i
];
int
off
=
offsets
[
i
];
switch
(
typeCodes
[
i
])
{
case
'Z'
:
...
...
@@ -1945,7 +1953,7 @@ public class ObjectStreamClass implements Serializable {
throw
new
NullPointerException
();
}
for
(
int
i
=
0
;
i
<
numPrimFields
;
i
++)
{
long
key
=
k
eys
[
i
];
long
key
=
writeK
eys
[
i
];
if
(
key
==
Unsafe
.
INVALID_FIELD_OFFSET
)
{
continue
;
// discard value
}
...
...
@@ -2006,7 +2014,7 @@ public class ObjectStreamClass implements Serializable {
switch
(
typeCodes
[
i
])
{
case
'L'
:
case
'['
:
vals
[
offsets
[
i
]]
=
unsafe
.
getObject
(
obj
,
k
eys
[
i
]);
vals
[
offsets
[
i
]]
=
unsafe
.
getObject
(
obj
,
readK
eys
[
i
]);
break
;
default
:
...
...
@@ -2027,7 +2035,7 @@ public class ObjectStreamClass implements Serializable {
throw
new
NullPointerException
();
}
for
(
int
i
=
numPrimFields
;
i
<
fields
.
length
;
i
++)
{
long
key
=
k
eys
[
i
];
long
key
=
writeK
eys
[
i
];
if
(
key
==
Unsafe
.
INVALID_FIELD_OFFSET
)
{
continue
;
// discard value
}
...
...
test/java/io/Serializable/6966692/Attack.java
0 → 100644
浏览文件 @
3f2298d8
/*
* @test
* @bug 6966692
* @summary defaultReadObject can set a field multiple times
* @run shell Test6966692.sh
*/
import
java.io.*
;
public
class
Attack
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
attack
(
setup
());
}
/** Returned data has Victim with two aaaa fields. */
private
static
byte
[]
setup
()
throws
Exception
{
Victim
victim
=
new
Victim
();
ByteArrayOutputStream
byteOut
=
new
ByteArrayOutputStream
();
ObjectOutputStream
out
=
new
ObjectOutputStream
(
byteOut
);
out
.
writeObject
(
victim
);
out
.
close
();
byte
[]
data
=
byteOut
.
toByteArray
();
String
str
=
new
String
(
data
,
0
);
// hibyte is 0
str
=
str
.
replaceAll
(
"bbbb"
,
"aaaa"
);
str
.
getBytes
(
0
,
data
.
length
,
data
,
0
);
// ignore hibyte
return
data
;
}
private
static
void
attack
(
byte
[]
data
)
throws
Exception
{
ObjectInputStream
in
=
new
ObjectInputStream
(
new
ByteArrayInputStream
(
data
)
);
Victim
victim
=
(
Victim
)
in
.
readObject
();
System
.
out
.
println
(
victim
+
" "
+
victim
.
aaaa
);
}
}
test/java/io/Serializable/6966692/README
0 → 100644
浏览文件 @
3f2298d8
Testcase shows default deserialisation of the Victim having two values for the same field.
Probably requires dual core to run successfully.
Reading thread is warmed up so that it can easily win the race for the demonstration, but this means we need to make the field volatile.
Typical output:
Victim@1551f60 BBBB
Victim@1551f60 AAAA
The output when its fixed is,
Victim@1975b59 AAAA
Victim@1975b59 AAAA - The value is retained
and when it is not fixed, it shows something like
Victim@173a10f AAAA
Victim@173a10f BBBB - the value of the object gets set again and hence is different. This is a bug
Look at the
AAAA AAAA
and
AAAA BBBB
test/java/io/Serializable/6966692/Test6966692.sh
0 → 100644
浏览文件 @
3f2298d8
#!/bin/sh
if
[
"
${
TESTSRC
}
"
=
""
]
then
TESTSRC
=
.
fi
if
[
"
${
TESTJAVA
}
"
=
""
]
then
PARENT
=
`
dirname
\`
which java
\`
`
TESTJAVA
=
`
dirname
${
PARENT
}
`
echo
"TESTJAVA not set, selecting "
${
TESTJAVA
}
echo
"If this is incorrect, try setting the variable manually."
fi
if
[
"
${
TESTCLASSES
}
"
=
""
]
then
echo
"TESTCLASSES not set. Test cannot execute. Failed."
exit
1
fi
BIT_FLAG
=
""
# set platform-dependent variables
OS
=
`
uname
-s
`
case
"
$OS
"
in
SunOS
|
Linux
)
NULL
=
/dev/null
PS
=
":"
FS
=
"/"
## for solaris, linux it's HOME
FILE_LOCATION
=
$HOME
if
[
-f
${
FILE_LOCATION
}${
FS
}
JDK64BIT
-a
${
OS
}
=
"SunOS"
]
then
BIT_FLAG
=
`
cat
${
FILE_LOCATION
}${
FS
}
JDK64BIT |
grep
-v
'^#'
`
fi
;;
Windows_
*
)
NULL
=
NUL
PS
=
";"
FS
=
"
\\
"
;;
*
)
echo
"Unrecognized system!"
exit
1
;
;;
esac
JEMMYPATH
=
${
CPAPPEND
}
CLASSPATH
=
.
${
PS
}${
TESTCLASSES
}${
PS
}${
JEMMYPATH
}
;
export
CLASSPATH
THIS_DIR
=
`
pwd
`
${
TESTJAVA
}${
FS
}
bin
${
FS
}
java
${
BIT_FLAG
}
-version
cp
${
TESTSRC
}${
FS
}*
.java
.
chmod
777
*
.java
${
TESTJAVA
}${
FS
}
bin
${
FS
}
javac
*
.java
${
TESTJAVA
}${
FS
}
bin
${
FS
}
java
${
BIT_FLAG
}
Attack
>
test.out 2>&1
cat
test.out
STATUS
=
0
egrep
"^Victim.*BBBB.*AAAA|^Victim.*AAAA.*BBBB"
test.out
if
[
$?
=
0
]
then
STATUS
=
1
else
egrep
"^Victim.*BBBB.*BBBB|^Victim.*AAAA.*AAAA"
test.out
if
[
$?
!=
0
]
;
then
STATUS
=
1
fi
fi
exit
$STATUS
test/java/io/Serializable/6966692/Victim.java
0 → 100644
浏览文件 @
3f2298d8
import
java.io.*
;
public
class
Victim
implements
Serializable
{
public
volatile
Object
aaaa
=
"AAAA"
;
// must be volatile...
private
final
Object
aabb
=
new
Show
(
this
);
public
Object
bbbb
=
"BBBB"
;
}
class
Show
implements
Serializable
{
private
final
Victim
victim
;
public
Show
(
Victim
victim
)
{
this
.
victim
=
victim
;
}
private
void
readObject
(
java
.
io
.
ObjectInputStream
in
)
throws
IOException
,
ClassNotFoundException
{
in
.
defaultReadObject
();
Thread
thread
=
new
Thread
(
new
Runnable
()
{
public
void
run
()
{
for
(;;)
{
Object
a
=
victim
.
aaaa
;
if
(
a
!=
null
)
{
System
.
err
.
println
(
victim
+
" "
+
a
);
break
;
}
}
}});
thread
.
start
();
// Make sure we are running compiled whilst serialisation is done interpreted.
try
{
Thread
.
sleep
(
1000
);
}
catch
(
java
.
lang
.
InterruptedException
exc
)
{
Thread
.
currentThread
().
interrupt
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录