Commit dffd5831 authored by Max Kellermann's avatar Max Kellermann

test/fuzzer: a simple fuzzer using libFuzzer

This commit adds some basic infrastructure for fuzzers, and adds a fuzzer for the CUE sheet parser.
parent 8358b34e
...@@ -112,6 +112,13 @@ if get_option('buildtype') != 'debug' ...@@ -112,6 +112,13 @@ if get_option('buildtype') != 'debug'
] ]
endif endif
if get_option('fuzzer')
fuzzer_flags = ['-fsanitize=fuzzer,address,undefined']
add_global_arguments(fuzzer_flags, language: 'cpp')
add_global_arguments(fuzzer_flags, language: 'c')
add_global_link_arguments(fuzzer_flags, language: 'cpp')
endif
add_global_arguments(common_cxxflags + compiler.get_supported_arguments(test_cxxflags), language: 'cpp') add_global_arguments(common_cxxflags + compiler.get_supported_arguments(test_cxxflags), language: 'cpp')
add_global_arguments(common_cflags + c_compiler.get_supported_arguments(test_cflags), language: 'c') add_global_arguments(common_cflags + c_compiler.get_supported_arguments(test_cflags), language: 'c')
add_global_link_arguments(compiler.get_supported_link_arguments(test_ldflags), language: 'cpp') add_global_link_arguments(compiler.get_supported_link_arguments(test_ldflags), language: 'cpp')
...@@ -502,6 +509,7 @@ mpd = build_target( ...@@ -502,6 +509,7 @@ mpd = build_target(
chromaprint_dep, chromaprint_dep,
], ],
link_args: link_args, link_args: link_args,
build_by_default: not get_option('fuzzer'),
install: not is_android and not is_haiku, install: not is_android and not is_haiku,
) )
...@@ -542,3 +550,7 @@ subdir('doc') ...@@ -542,3 +550,7 @@ subdir('doc')
if get_option('test') if get_option('test')
subdir('test') subdir('test')
endif endif
if get_option('fuzzer')
subdir('test/fuzzer')
endif
...@@ -17,6 +17,7 @@ option('systemd_user_unit_dir', type: 'string', description: 'systemd user servi ...@@ -17,6 +17,7 @@ option('systemd_user_unit_dir', type: 'string', description: 'systemd user servi
# #
option('test', type: 'boolean', value: false, description: 'Build the unit tests and debug programs') option('test', type: 'boolean', value: false, description: 'Build the unit tests and debug programs')
option('fuzzer', type: 'boolean', value: false, description: 'Build fuzzers (requires libFuzzer)')
# #
# Android # Android
......
#include "playlist/cue/CueParser.hxx"
#include "util/IterableSplitString.hxx"
#include <string>
#include <string_view>
extern "C" {
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
CueParser parser;
const std::string_view src{(const char *)data, size};
for (const auto line : IterableSplitString(src, '\n')) {
parser.Feed(std::string(line).c_str());
parser.Get();
}
parser.Finish();
parser.Get();
return 0;
}
executable(
'FuzzCueParser',
'FuzzCueParser.cxx',
'../../src/playlist/cue/CueParser.cxx',
include_directories: inc,
dependencies: [
tag_dep,
],
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment