1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 21:06:38 +02:00

tests: convert fuzzing sources to C++

This commit is contained in:
Sébastien Helleu
2025-05-07 21:15:51 +02:00
parent d74fc99fe1
commit 38bf51ccfb
5 changed files with 24 additions and 10 deletions
+3 -1
View File
@@ -19,6 +19,8 @@
# along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
#
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})
@@ -21,15 +21,17 @@
/* Fuzz testing on WeeChat core calc functions */
extern "C"
{
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#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;
@@ -21,6 +21,8 @@
/* Fuzz testing on WeeChat core crypto functions */
extern "C"
{
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
@@ -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;
@@ -21,6 +21,8 @@
/* Fuzz testing on WeeChat core string functions */
extern "C"
{
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
@@ -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);
@@ -21,6 +21,8 @@
/* Fuzz testing on WeeChat core UTF-8 functions */
extern "C"
{
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
@@ -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;