Merge pull request #1972 from catenacyber/ossfuzz

Adds fuzz target for oss-fuzz integration
This commit is contained in:
Ward Fisher 2021-06-17 14:32:48 -06:00 committed by GitHub
commit 1a7ee7170a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -2257,6 +2257,8 @@ IF(ENABLE_TESTS)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ncdap_test/pingurl.c ${CMAKE_CURRENT_BINARY_DIR}/dap4_test/pingurl4.c @ONLY NEWLINE_STYLE LF)
ENDIF()
add_subdirectory(fuzz)
####
# Export files
####

4
fuzz/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
if(DEFINED ENV{LIB_FUZZING_ENGINE})
add_executable(fuzz_open fuzz_open.c)
target_link_libraries(fuzz_open netcdf $ENV{LIB_FUZZING_ENGINE})
endif()

17
fuzz/fuzz_open.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <netcdf.h>
#include <netcdf_mem.h>
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
int ncid;
if (nc_open_mem("/tmp/fuzz.nc", 0, Size, (void *) Data, &ncid) == NC_NOERR) {
nc_close(ncid);
}
return 0;
}