Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
057fe24c
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
057fe24c
编写于
8月 15, 2022
作者:
O
openharmony_ci
提交者:
Gitee
8月 15, 2022
浏览文件
操作
浏览文件
下载
差异文件
!456 指针混淆及safe-unlink测试用例优化
Merge pull request !456 from Far/master
上级
00eb0886
3748cf9e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
37 deletion
+69
-37
libc-test/src/regression/malloc-free-performance.c
libc-test/src/regression/malloc-free-performance.c
+1
-1
libc-test/src/regression/malloc-modify-pointer.c
libc-test/src/regression/malloc-modify-pointer.c
+33
-10
libc-test/src/regression/malloc-safe-unlink.c
libc-test/src/regression/malloc-safe-unlink.c
+35
-26
未找到文件。
libc-test/src/regression/malloc-free-performance.c
浏览文件 @
057fe24c
...
...
@@ -190,5 +190,5 @@ int main(int argc, char *argv[])
t_printf
(
"Malloc and free %d times cost %lf s
\n
"
,
MALLOC_TIME
,
cost
/
NANOSEC_PER_SEC
);
return
t_status
;
return
0
;
}
libc-test/src/regression/malloc-modify-pointer.c
浏览文件 @
057fe24c
...
...
@@ -25,20 +25,43 @@ static void handler(int s)
{
}
volatile
uintptr_t
*
p0
;
volatile
uintptr_t
*
p1
;
volatile
void
*
tmp
;
static
int
child
(
void
)
{
uintptr_t
*
p
=
(
uintptr_t
*
)
malloc
(
10
*
sizeof
(
uintptr_t
));
if
(
!
p
)
{
p0
=
(
uintptr_t
*
)
malloc
(
10
*
sizeof
(
uintptr_t
));
if
(
!
p0
)
{
t_error
(
"Malloc failed:%s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
/* Malloc a dividing chunk to avoid combination of neighbouring freed chunk */
tmp
=
malloc
(
10
*
sizeof
(
uintptr_t
));
/* Malloc another chunk to get a key */
p1
=
(
uintptr_t
*
)
malloc
(
10
*
sizeof
(
uintptr_t
));
if
(
!
p1
)
{
t_error
(
"Malloc failed:%s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
/* Malloc a dividing chunk to avoid combination of neighbouring freed chunk */
malloc
(
10
*
sizeof
(
uintptr_t
));
free
(
p
);
/* Reverse the pointer getting an illegal pointer */
*
p
=
~*
p
;
/* Malloc same chunk to trigger illegal pointer access */
p
=
(
uintptr_t
*
)
malloc
(
10
*
sizeof
(
uintptr_t
));
tmp
=
malloc
(
10
*
sizeof
(
uintptr_t
));
free
((
void
*
)
p0
);
free
((
void
*
)
p1
);
uintptr_t
*
fake_ptr
=
(
uintptr_t
*
)((
uintptr_t
)((
char
*
)
p1
-
sizeof
(
size_t
)
*
2
)
^
(
uintptr_t
)
p0
[
0
]);
p0
[
0
]
=
(
uintptr_t
)
fake_ptr
;
p1
[
0
]
=
(
uintptr_t
)
fake_ptr
;
/*
* The init procedure makes the freelist unpredictable. To make sure to trigger the ivalid ptr
* acess, here we create as many chunks as possible to make sure there are enough chunks in
* bin[j] of size "10 * sizeof(uintptr_t)". Basically this is heap spray.
*/
for
(
int
i
=
0
;
i
<
512
;
++
i
)
{
tmp
=
malloc
(
10
*
sizeof
(
uintptr_t
));
}
return
0
;
}
...
...
@@ -91,12 +114,12 @@ int main(int argc, char *argv[])
}
if
(
WIFSIGNALED
(
status
))
{
if
(
WTERMSIG
(
status
)
!=
SIGSEGV
)
{
if
(
WTERMSIG
(
status
)
!=
SIGSEGV
&&
WTERMSIG
(
status
)
!=
SIGILL
)
{
t_error
(
"%s child process out with %s
\n
"
,
argv
[
0
],
strsignal
(
WTERMSIG
(
status
)));
return
-
1
;
}
}
else
{
t_error
(
"%s child process finished normally
\n
"
,
argv
[
0
]);
}
return
t_status
;
return
0
;
}
libc-test/src/regression/malloc-safe-unlink.c
浏览文件 @
057fe24c
...
...
@@ -25,37 +25,46 @@ static void handler(int s)
{
}
static
int
child
(
void
)
volatile
void
*
tmp
;
int
set_devide_chunk
(
size_t
size
)
{
uintptr_t
*
c0
=
(
uintptr_t
*
)
malloc
(
sizeof
(
uintptr_t
)
*
10
);
if
(
!
c0
)
{
t_error
(
"Malloc failed: %s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
/* Malloc a dividing chunk to avoiding combination of neighbouring chunk */
malloc
(
sizeof
(
uintptr_t
)
*
10
);
/* Malloc another chunk */
uintptr_t
*
c1
=
(
uintptr_t
*
)
malloc
(
sizeof
(
uintptr_t
)
*
10
);
if
(
!
c1
)
{
if
(
!
(
tmp
=
malloc
(
size
)))
{
t_error
(
"Malloc failed: %s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
/* Malloc a dividing chunk to avoiding combination of neighbouring chunk */
malloc
(
sizeof
(
uintptr_t
)
*
10
);
return
0
;
}
static
int
child
(
void
)
{
uintptr_t
*
c
;
uintptr_t
*
temp
;
/*
Free the chunk, now they are in same list
*/
free
(
c0
);
free
(
c1
)
;
/*
Set first dividing chunk
*/
if
(
set_devide_chunk
(
sizeof
(
size_t
)))
return
-
1
;
/* Exchange the next and prev pointer in chunk */
/* They are legal but wrongly pointing */
uintptr_t
temp
=
c0
[
0
];
c0
[
0
]
=
c0
[
1
];
c0
[
1
]
=
temp
;
/*
* The init procedure makes the freelist unpredictable. To make sure trigger the safe-unlink
* check, Here we create as many chunks as possible to make sure there are enough chunks in
* bin[0] and malloc again. Basically this is heap spray.
*/
for
(
int
i
=
0
;
i
<
512
;
++
i
)
{
if
(
set_devide_chunk
(
sizeof
(
size_t
)))
return
-
1
;
c
=
(
uintptr_t
*
)
malloc
(
sizeof
(
uintptr_t
));
if
(
!
c
)
{
t_error
(
"Malloc failed: %s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
free
(
c
);
/* exchange the prev and next pointer */
uintptr_t
temp
=
c
[
0
];
c
[
0
]
=
c
[
1
];
c
[
1
]
=
temp
;
}
/* Malloc again, trigger the safe-unlink check */
c0
=
(
uintptr_t
*
)
malloc
(
sizeof
(
uintptr_t
)
*
10
);
c1
=
(
uintptr_t
*
)
malloc
(
sizeof
(
uintptr_t
)
*
10
);
return
0
;
}
...
...
@@ -108,12 +117,12 @@ int main(int argc, char *argv[])
}
if
(
WIFSIGNALED
(
status
))
{
if
(
WTERMSIG
(
status
)
!=
SIGSEGV
)
{
if
(
WTERMSIG
(
status
)
!=
SIGSEGV
&&
WTERMSIG
(
status
)
!=
SIGILL
)
{
t_error
(
"%s child process out with %s
\n
"
,
argv
[
0
],
strsignal
(
WTERMSIG
(
status
)));
return
-
1
;
}
}
else
{
t_error
(
"%s child process finished normally
\n
"
,
argv
[
0
]);
}
return
t_status
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录