Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
79af8736
Commit
79af8736
authored
Jul 31, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fuzz test for JSON parser
parent
846503b3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
6 deletions
+57
-6
CMakeLists.txt
CMakeLists.txt
+41
-5
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+3
-1
libcaf_core/fuzz/src/json-parse.cpp
libcaf_core/fuzz/src/json-parse.cpp
+13
-0
No files found.
CMakeLists.txt
View file @
79af8736
...
...
@@ -76,6 +76,21 @@ if(MSVC AND CAF_SANITIZERS)
message
(
FATAL_ERROR
"Sanitizer builds are currently not supported on MSVC"
)
endif
()
# -- when building fuzzing targets, we skip unit tests and install targets -----
if
(
CAF_SANITIZERS MATCHES
"fuzzer"
)
message
(
STATUS
"Build fuzz targets and skip unit test targets"
)
set
(
CAF_ADD_FUZZ_TARGETS ON
)
set
(
CAF_ADD_TEST_TARGETS OFF
)
else
()
set
(
CAF_ADD_FUZZ_TARGETS OFF
)
if
(
CAF_ENABLE_TESTING
)
set
(
CAF_ADD_TEST_TARGETS ON
)
else
()
set
(
CAF_ADD_TEST_TARGETS OFF
)
endif
()
endif
()
# -- get dependencies that are used in more than one module --------------------
if
(
CAF_ENABLE_OPENSSL_MODULE OR CAF_ENABLE_NET_MODULE
)
...
...
@@ -109,7 +124,7 @@ endif()
# -- unit testing setup / caf_add_test_suites function ------------------------
if
(
CAF_
ENABLE_TESTING
)
if
(
CAF_
ADD_TEST_TARGETS
)
enable_testing
()
function
(
caf_add_test_suites target
)
foreach
(
suiteName
${
ARGN
}
)
...
...
@@ -122,6 +137,9 @@ if(CAF_ENABLE_TESTING)
endif
()
endforeach
()
endfunction
()
else
()
function
(
caf_add_test_suites
)
endfunction
()
endif
()
# -- make sure we have at least C++17 available --------------------------------
...
...
@@ -315,7 +333,8 @@ endfunction()
# ...
# )
function
(
caf_add_component name
)
set
(
varargs DEPENDENCIES HEADERS SOURCES TEST_SOURCES TEST_SUITES ENUM_TYPES
)
set
(
varargs DEPENDENCIES HEADERS SOURCES TEST_SOURCES TEST_SUITES ENUM_TYPES
FUZZ_TESTS
)
cmake_parse_arguments
(
CAF_ADD_COMPONENT
""
""
"
${
varargs
}
"
${
ARGN
}
)
if
(
NOT CAF_ADD_COMPONENT_HEADERS
)
message
(
FATAL_ERROR
"Cannot add CAF component without at least one header."
)
...
...
@@ -339,7 +358,7 @@ function(caf_add_component name)
add_library
(
${
pub_lib_target
}
"
${
PROJECT_SOURCE_DIR
}
/cmake/dummy.cpp"
$<TARGET_OBJECTS:
${
obj_lib_target
}
>
)
if
(
CAF_
ENABLE_TESTING
AND CAF_ADD_COMPONENT_TEST_SOURCES
)
if
(
CAF_
ADD_TEST_TARGETS
AND CAF_ADD_COMPONENT_TEST_SOURCES
)
set
(
tst_bin_target
"caf-
${
name
}
-test"
)
list
(
APPEND targets
${
tst_bin_target
}
)
add_executable
(
${
tst_bin_target
}
...
...
@@ -353,6 +372,23 @@ function(caf_add_component name)
caf_add_test_suites
(
${
tst_bin_target
}
${
CAF_ADD_COMPONENT_TEST_SUITES
}
)
endif
()
endif
()
if
(
CAF_ADD_FUZZ_TARGETS AND CAF_ADD_COMPONENT_FUZZ_TESTS
)
foreach
(
fuzz_name
${
CAF_ADD_COMPONENT_FUZZ_TESTS
}
)
set
(
fuzz_bin_target
"caf-
${
name
}
-
${
fuzz_name
}
"
)
add_executable
(
${
fuzz_bin_target
}
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/fuzz/src/
${
fuzz_name
}
.cpp"
$<TARGET_OBJECTS:
${
obj_lib_target
}
>
)
target_link_libraries
(
${
fuzz_bin_target
}
PRIVATE CAF::internal
${
CAF_ADD_COMPONENT_DEPENDENCIES
}
)
if
(
EXISTS
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/fuzz/include"
)
target_include_directories
(
${
fuzz_bin_target
}
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/fuzz/include"
)
endif
()
target_include_directories
(
${
fuzz_bin_target
}
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
"
"
${
CMAKE_CURRENT_BINARY_DIR
}
"
)
endforeach
()
endif
()
target_link_libraries
(
${
pub_lib_target
}
${
CAF_ADD_COMPONENT_DEPENDENCIES
}
)
if
(
CAF_ADD_COMPONENT_ENUM_TYPES
)
foreach
(
enum_name
${
CAF_ADD_COMPONENT_ENUM_TYPES
}
)
...
...
@@ -393,11 +429,11 @@ if(CAF_ENABLE_OPENSSL_MODULE)
add_subdirectory
(
libcaf_openssl
)
endif
()
if
(
CAF_ENABLE_EXAMPLES
)
if
(
CAF_ENABLE_EXAMPLES
AND NOT CAF_ADD_FUZZ_TARGETS
)
add_subdirectory
(
examples
)
endif
()
if
(
CAF_ENABLE_TOOLS
)
if
(
CAF_ENABLE_TOOLS
AND NOT CAF_ADD_FUZZ_TARGETS
)
add_subdirectory
(
tools
)
endif
()
...
...
libcaf_core/CMakeLists.txt
View file @
79af8736
...
...
@@ -362,7 +362,9 @@ caf_add_component(
unit
unordered_flat_map
uri
uuid
)
uuid
FUZZ_TESTS
json-parse
)
if
(
CAF_ENABLE_TESTING AND CAF_ENABLE_EXCEPTIONS
)
caf_add_test_suites
(
caf-core-test custom_exception_handler
)
...
...
libcaf_core/fuzz/src/json-parse.cpp
0 → 100644
View file @
79af8736
#include "caf/detail/json.hpp"
using
namespace
caf
;
thread_local
detail
::
monotonic_buffer_resource
buf
;
extern
"C"
int
LLVMFuzzerTestOneInput
(
const
uint8_t
*
data
,
size_t
size
)
{
buf
.
reclaim
();
std
::
string_view
json_text
{
reinterpret_cast
<
const
char
*>
(
data
),
size
};
string_parser_state
ps
{
json_text
.
begin
(),
json_text
.
end
()};
detail
::
json
::
parse
(
ps
,
&
buf
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment