Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
2986c80d
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
接近 2 年 前同步成功
通知
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看板
未验证
提交
2986c80d
编写于
7月 17, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 17, 2023
浏览文件
操作
浏览文件
下载
差异文件
!987 fix fread buffer overflow
Merge pull request !987 from Wang Yaofeng/fread_overflow
上级
e932e671
c753c50b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
6 deletion
+49
-6
libc-test/src/functionalext/supplement/stdio/fread.c
libc-test/src/functionalext/supplement/stdio/fread.c
+40
-1
porting/linux/user/src/stdio/__stdio_read.c
porting/linux/user/src/stdio/__stdio_read.c
+8
-3
porting/linux/user/src/stdio/fread.c
porting/linux/user/src/stdio/fread.c
+1
-2
未找到文件。
libc-test/src/functionalext/supplement/stdio/fread.c
浏览文件 @
2986c80d
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
* limitations under the License.
* limitations under the License.
*/
*/
#include <sys/stat.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdlib.h>
#include "functionalext.h"
#include "functionalext.h"
...
@@ -116,11 +118,48 @@ void fread_0400(void)
...
@@ -116,11 +118,48 @@ void fread_0400(void)
remove
(
ptr
);
remove
(
ptr
);
}
}
/**
* @tc.name : fread_0500
* @tc.desc : Verify that the return value of syscall have been processed correctly
* @tc.level : Level 2
*/
#define FREAD_0500_BUFSZ (4097)
void
fread_0500
(
void
)
{
pid_t
pid
=
fork
();
if
(
pid
==
-
1
)
{
perror
(
"fread_0500 fork:"
);
exit
(
-
1
);
}
/* child */
if
(
pid
==
0
)
{
/* make sure parent opening the status file */
sleep
(
1
);
exit
(
-
1
);
}
char
buf
[
FREAD_0500_BUFSZ
]
=
{
0
};
sprintf
(
buf
,
"/proc/%d/status"
,
pid
);
FILE
*
fStatus
=
fopen
(
buf
,
"rb"
);
EXPECT_PTRNE
(
"fread_0500"
,
fStatus
,
NULL
);
/* wait child exit, and status file of child will disappear */
int
status
=
0
;
pid_t
w
=
wait
(
&
status
);
/* read >4K data from file, check if return correctly */
size_t
rsize
=
fread
(
buf
,
1
,
FREAD_0500_BUFSZ
,
fStatus
);
EXPECT_EQ
(
"fread_0500"
,
rsize
,
0
);
fclose
(
fStatus
);
}
TEST_FUN
G_Fun_Array
[]
=
{
TEST_FUN
G_Fun_Array
[]
=
{
fread_0100
,
fread_0100
,
fread_0200
,
fread_0200
,
fread_0300
,
fread_0300
,
fread_0400
,
fread_0400
,
fread_0500
,
};
};
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
...
@@ -131,4 +170,4 @@ int main(int argc, char *argv[])
...
@@ -131,4 +170,4 @@ int main(int argc, char *argv[])
}
}
return
t_status
;
return
t_status
;
}
}
\ No newline at end of file
porting/linux/user/src/stdio/__stdio_read.c
浏览文件 @
2986c80d
...
@@ -3,7 +3,12 @@
...
@@ -3,7 +3,12 @@
size_t
__stdio_readx
(
FILE
*
f
,
unsigned
char
*
buf
,
size_t
len
)
size_t
__stdio_readx
(
FILE
*
f
,
unsigned
char
*
buf
,
size_t
len
)
{
{
return
syscall
(
SYS_read
,
f
->
fd
,
buf
,
len
);
ssize_t
cnt
=
syscall
(
SYS_read
,
f
->
fd
,
buf
,
len
);
if
(
cnt
<=
0
)
{
f
->
flags
|=
cnt
?
F_ERR
:
F_EOF
;
return
0
;
}
return
cnt
;
}
}
size_t
__stdio_read
(
FILE
*
f
,
unsigned
char
*
buf
,
size_t
len
)
size_t
__stdio_read
(
FILE
*
f
,
unsigned
char
*
buf
,
size_t
len
)
...
@@ -21,8 +26,8 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
...
@@ -21,8 +26,8 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
return
0
;
return
0
;
}
}
if
(
cnt
<=
iov_buf
[
0
].
iov_len
)
{
if
(
cnt
<=
iov_buf
[
0
].
iov_len
)
{
return
cnt
;
return
cnt
;
}
}
cnt
-=
iov_buf
[
0
].
iov_len
;
cnt
-=
iov_buf
[
0
].
iov_len
;
f
->
rpos
=
f
->
buf
;
f
->
rpos
=
f
->
buf
;
f
->
rend
=
f
->
buf
+
cnt
;
f
->
rend
=
f
->
buf
+
cnt
;
...
...
porting/linux/user/src/stdio/fread.c
浏览文件 @
2986c80d
...
@@ -69,8 +69,7 @@ size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f)
...
@@ -69,8 +69,7 @@ size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f)
/* Read the remainder directly */
/* Read the remainder directly */
for
(;
l
;
l
-=
k
,
dest
+=
k
)
{
for
(;
l
;
l
-=
k
,
dest
+=
k
)
{
k
=
f
->
readx
(
f
,
dest
,
l
);
k
=
f
->
readx
(
f
,
dest
,
l
);
if
(
k
<=
0
)
{
if
(
!
k
)
{
f
->
flags
|=
(
k
==
0
?
F_EOF
:
F_ERR
);
break
;
break
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录