diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index 8ca2b8d5a..240002726 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -19,6 +19,8 @@ # along with WeeChat. If not, see . # +enable_language(CXX) + if(NOT DEFINED ENV{LIB_FUZZING_ENGINE}) set(ENV{LIB_FUZZING_ENGINE} "-fsanitize=address,fuzzer") endif() @@ -94,7 +96,7 @@ list(APPEND FUZZ_TARGET_DEPS set(FUZZ_CORE_TARGETS calc crypto string utf8) foreach(fuzz_target ${FUZZ_CORE_TARGETS}) - add_executable(weechat_core_${fuzz_target}_fuzzer core/${fuzz_target}-fuzzer.c) + add_executable(weechat_core_${fuzz_target}_fuzzer core/${fuzz_target}-fuzzer.cc) target_link_libraries(weechat_core_${fuzz_target}_fuzzer ${FUZZ_TARGET_LINK} coverage_config) set_target_properties(weechat_core_${fuzz_target}_fuzzer PROPERTIES LINK_FLAGS "$ENV{LIB_FUZZING_ENGINE}") add_dependencies(weechat_core_${fuzz_target}_fuzzer ${FUZZ_TARGET_DEPS}) diff --git a/tests/fuzz/core/calc-fuzzer.c b/tests/fuzz/core/calc-fuzzer.cc similarity index 93% rename from tests/fuzz/core/calc-fuzzer.c rename to tests/fuzz/core/calc-fuzzer.cc index b7e0619a8..85719cefb 100644 --- a/tests/fuzz/core/calc-fuzzer.c +++ b/tests/fuzz/core/calc-fuzzer.cc @@ -21,15 +21,17 @@ /* Fuzz testing on WeeChat core calc functions */ +extern "C" +{ #include #include #include #include #include "src/core/core-calc.h" +} -int -LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { char *str; diff --git a/tests/fuzz/core/crypto-fuzzer.c b/tests/fuzz/core/crypto-fuzzer.cc similarity index 98% rename from tests/fuzz/core/crypto-fuzzer.c rename to tests/fuzz/core/crypto-fuzzer.cc index 00c5aead5..a8394412d 100644 --- a/tests/fuzz/core/crypto-fuzzer.c +++ b/tests/fuzz/core/crypto-fuzzer.cc @@ -21,6 +21,8 @@ /* Fuzz testing on WeeChat core crypto functions */ +extern "C" +{ #include #include #include @@ -33,8 +35,9 @@ extern char *weecrypto_hash_algo_string[]; extern int weecrypto_hash_algo[]; +} -int +extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { char *str, hash[1024], *result; diff --git a/tests/fuzz/core/string-fuzzer.c b/tests/fuzz/core/string-fuzzer.cc similarity index 97% rename from tests/fuzz/core/string-fuzzer.c rename to tests/fuzz/core/string-fuzzer.cc index 86fe59722..e3d0cd1f5 100644 --- a/tests/fuzz/core/string-fuzzer.c +++ b/tests/fuzz/core/string-fuzzer.cc @@ -21,6 +21,8 @@ /* Fuzz testing on WeeChat core string functions */ +extern "C" +{ #include #include #include @@ -31,10 +33,11 @@ #include "src/core/core-config.h" #include "src/core/core-string.h" #include "src/plugins/weechat-plugin.h" +} regex_t global_regex; -int +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { (void) argc; @@ -56,10 +59,11 @@ callback_replace (void *data, const char *text) return strdup ("z"); } -int +extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { - char *str, *str2, **str_dyn, *result, *masks[3] = { "a*", "b*", NULL}; + const char *masks[3] = { "a*", "b*", NULL}; + char *str, *str2, **str_dyn, *result; char **argv, *buffer; const char *name; int argc, flags, num_tags, priority; @@ -186,7 +190,7 @@ LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) string_parse_size (str); - buffer = malloc ((size * 4) + 8 + 1); + buffer = (char *)malloc ((size * 4) + 8 + 1); string_base16_encode (str, size, buffer); string_base16_decode (str, buffer); string_base32_encode (str, size, buffer); diff --git a/tests/fuzz/core/utf8-fuzzer.c b/tests/fuzz/core/utf8-fuzzer.cc similarity index 98% rename from tests/fuzz/core/utf8-fuzzer.c rename to tests/fuzz/core/utf8-fuzzer.cc index 9d8bac23e..11506133e 100644 --- a/tests/fuzz/core/utf8-fuzzer.c +++ b/tests/fuzz/core/utf8-fuzzer.cc @@ -21,6 +21,8 @@ /* Fuzz testing on WeeChat core UTF-8 functions */ +extern "C" +{ #include #include #include @@ -28,8 +30,9 @@ #include "src/core/core-config.h" #include "src/core/core-utf8.h" +} -int +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { (void) argc; @@ -40,7 +43,7 @@ LLVMFuzzerInitialize(int *argc, char ***argv) return 0; } -int +extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { char *str, *str2, utf8_char[5], *error;