Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
bd1a3750
T
Third Party CJSON
项目概览
OpenHarmony
/
Third Party CJSON
大约 1 年 前同步成功
通知
6
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party CJSON
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bd1a3750
编写于
8月 24, 2019
作者:
R
Randy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add fuzzer driver, integrate with build system
上级
2d6db59c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
76 addition
and
9 deletion
+76
-9
fuzzing/CMakeLists.txt
fuzzing/CMakeLists.txt
+5
-0
fuzzing/cjson_read_fuzzer.cc
fuzzing/cjson_read_fuzzer.cc
+15
-9
fuzzing/fuzz_main.c
fuzzing/fuzz_main.c
+56
-0
未找到文件。
fuzzing/CMakeLists.txt
浏览文件 @
bd1a3750
...
...
@@ -26,3 +26,8 @@ if (ENABLE_FUZZING)
endif
()
if
(
ENABLE_CJSON_TEST
)
ADD_EXECUTABLE
(
fuzz_main fuzz_main.c
)
TARGET_LINK_LIBRARIES
(
fuzz_main cjson
)
endif
()
\ No newline at end of file
fuzzing/cjson_read_fuzzer.cc
浏览文件 @
bd1a3750
...
...
@@ -4,9 +4,17 @@
#include "../cJSON.h"
extern
"C"
int
LLVMFuzzerTestOneInput
(
const
uint8_t
*
data
,
size_t
size
)
#ifdef __cplusplus
extern
"C"
#endif
int
LLVMFuzzerTestOneInput
(
const
uint8_t
*
data
,
size_t
size
)
{
cJSON
*
json
;
size_t
offset
=
4
;
unsigned
char
*
copied
;
char
*
printed_json
=
NULL
;
int
minify
,
require_termination
,
formatted
,
buffered
;
if
(
size
<=
offset
)
return
0
;
if
(
data
[
0
]
!=
'1'
&&
data
[
0
]
!=
'0'
)
return
0
;
...
...
@@ -14,18 +22,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
if
(
data
[
2
]
!=
'1'
&&
data
[
2
]
!=
'0'
)
return
0
;
if
(
data
[
3
]
!=
'1'
&&
data
[
3
]
!=
'0'
)
return
0
;
int
minify
=
data
[
0
]
==
'1'
?
1
:
0
;
int
require_termination
=
data
[
1
]
==
'1'
?
1
:
0
;
int
formatted
=
data
[
2
]
==
'1'
?
1
:
0
;
int
buffered
=
data
[
3
]
==
'1'
?
1
:
0
;
minify
=
data
[
0
]
==
'1'
?
1
:
0
;
require_termination
=
data
[
1
]
==
'1'
?
1
:
0
;
formatted
=
data
[
2
]
==
'1'
?
1
:
0
;
buffered
=
data
[
3
]
==
'1'
?
1
:
0
;
unsigned
char
*
copied
=
(
unsigned
char
*
)
malloc
(
size
);
copied
=
(
unsigned
char
*
)
malloc
(
size
);
if
(
copied
==
NULL
)
return
0
;
memcpy
(
copied
,
data
,
size
);
copied
[
size
-
1
]
=
'\0'
;
cJSON
*
json
=
cJSON_ParseWithOpts
((
const
char
*
)
copied
+
offset
,
NULL
,
require_termination
);
json
=
cJSON_ParseWithOpts
((
const
char
*
)
copied
+
offset
,
NULL
,
require_termination
);
if
(
json
==
NULL
)
{
...
...
@@ -33,8 +41,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
return
0
;
}
char
*
printed_json
=
NULL
;
if
(
buffered
)
{
printed_json
=
cJSON_PrintBuffered
(
json
,
1
,
formatted
);
...
...
fuzzing/fuzz_main.c
0 → 100644
浏览文件 @
bd1a3750
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int
LLVMFuzzerTestOneInput
(
const
uint8_t
*
data
,
size_t
size
);
/* required by C90 */
#include "cjson_read_fuzzer.cc"
/* fuzz target entry point, works without libFuzzer */
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
f
;
char
*
buf
=
NULL
;
long
siz_buf
;
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"no input file
\n
"
);
goto
err
;
}
f
=
fopen
(
argv
[
1
],
"rb"
);
if
(
f
==
NULL
)
{
fprintf
(
stderr
,
"error opening input file %s
\n
"
,
argv
[
1
]);
goto
err
;
}
fseek
(
f
,
0
,
SEEK_END
);
siz_buf
=
ftell
(
f
);
rewind
(
f
);
if
(
siz_buf
<
1
)
goto
err
;
buf
=
(
char
*
)
malloc
((
size_t
)
siz_buf
);
if
(
buf
==
NULL
)
{
fprintf
(
stderr
,
"malloc() failed
\n
"
);
goto
err
;
}
if
(
fread
(
buf
,
(
size_t
)
siz_buf
,
1
,
f
)
!=
1
)
{
fprintf
(
stderr
,
"fread() failed
\n
"
);
goto
err
;
}
(
void
)
LLVMFuzzerTestOneInput
((
uint8_t
*
)
buf
,
(
size_t
)
siz_buf
);
err:
free
(
buf
);
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录