fuzz BUGFIX fix build issues with fuzz regression tests
This fixes multiple fuzz_regression_test issues.
First, if libyang was built with both ENABLE_BUILD_TESTS and
ENABLE_FUZZ_TARGETS, the fuzz harnesses wouldn't build as the test fuzz
corpus was copied into a directory of the same name, so a _fuzz postfix
was added to the fuzz harness executables.
The other fixes fix some build warnings and typos.
diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt
index add7283..8810760 100644
--- a/tests/fuzz/CMakeLists.txt
+++ b/tests/fuzz/CMakeLists.txt
@@ -5,20 +5,20 @@
if(FUZZER STREQUAL "AFL")
foreach(target_name IN LISTS fuzz_targets)
- add_executable(${target_name} ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>)
- target_link_libraries(${target_name} yang)
- target_link_libraries(${target_name} ${CMAKE_THREADS_LIB_INIT})
+ add_executable(${target_name}_fuzz ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>)
+ target_link_libraries(${target_name}_fuzz yang)
+ target_link_libraries(${target_name}_fuzz ${CMAKE_THREADS_LIB_INIT})
endforeach(target_name)
elseif(FUZZER STREQUAL "LibFuzzer")
foreach(target_name IN LISTS fuzz_targets)
- add_executable(${target_name} ${target_name}.c $<TARGET_OBJECTS:yangobj>)
+ add_executable(${target_name}_fuzz ${target_name}.c $<TARGET_OBJECTS:yangobj>)
set_source_files_properties(${target_name}.c PROPERTIES COMPILE_FLAGS "-fsanitize=fuzzer")
- target_link_libraries(${target_name} yang "-fsanitize=fuzzer")
+ target_link_libraries(${target_name}_fuzz yang "-fsanitize=fuzzer")
endforeach(target_name)
endif()
endif()
-if (ENABLE_TESTING)
+if (ENABLE_BUILD_TESTS)
add_executable(fuzz_regression_test fuzz_regression_test.c)
set(fuzz_regression_tests lys_parse_mem lyd_parse_mem)
foreach(target_name IN LISTS fuzz_regression_tests)
diff --git a/tests/fuzz/fuzz_regression_test.c b/tests/fuzz/fuzz_regression_test.c
index 53b2ec8..650c304 100644
--- a/tests/fuzz/fuzz_regression_test.c
+++ b/tests/fuzz/fuzz_regression_test.c
@@ -16,7 +16,6 @@
int status = 0;
int rc = 0;
struct stat path_stat;
- int i = 0;
if (argc != 3) {
fprintf(stderr, "invalid number of arguments. Call like this ./fuzz_regression_test fuzz_harness corpus_dir\n");
@@ -58,7 +57,7 @@
}
if (!WIFEXITED(status)) {
- fprintf(stderr, "test %s - %s failed\n", argv[1], argv[2]);
+ fprintf(stderr, "test %s - %s failed\n", argv[1], dir->d_name);
return EXIT_FAILURE;
}
diff --git a/tests/fuzz/lyd_parse_mem.c b/tests/fuzz/lyd_parse_mem.c
index cd4be88..e85d84a 100644
--- a/tests/fuzz/lyd_parse_mem.c
+++ b/tests/fuzz/lyd_parse_mem.c
@@ -74,7 +74,7 @@
memcpy(data, buf, len);
data[len] = 0;
- lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree);
+ lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree);
ly_ctx_destroy(ctx, NULL);
free(data);