Skip to content

Commit 8d1e09d

Browse files
committed
CMake: build fuzzers in standalone mode as part of BUILD_TESTING
1 parent 7e10ddc commit 8d1e09d

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,8 @@ proj_add_gie_test("GIGS-5208" "gigs/5208.gie")
108108
add_subdirectory(cli)
109109
add_subdirectory(unit)
110110
add_subdirectory(benchmark)
111+
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fuzzers")
112+
add_subdirectory(fuzzers)
113+
endif()
114+
115+

test/fuzzers/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if(NOT WIN32)
2+
3+
add_compile_options(${PROJ_CXX_WARN_FLAGS})
4+
5+
add_executable(proj_crs_to_crs_fuzzer proj_crs_to_crs_fuzzer.cpp)
6+
target_compile_definitions(proj_crs_to_crs_fuzzer PRIVATE -DSTANDALONE)
7+
target_link_libraries(proj_crs_to_crs_fuzzer PRIVATE ${PROJ_LIBRARIES})
8+
endif()

test/fuzzers/README.TXT

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ and call scripts in this directory.
88
The list of issues is in:
99
https://bugs.chromium.org/p/oss-fuzz/issues/list?q=proj4
1010

11-
- Build standard_fuzzer in a standalone mode:
12-
13-
$ g++ -g -std=c++11 standard_fuzzer.cpp -o standard_fuzzer -fvisibility=hidden -DSTANDALONE ../../build/lib/libproj.a -lpthread -lsqlite3 -I../../src -I../../include
11+
- Build proj_crs_to_crs_fuzzer in a standalone mode with the
12+
-DBUILD_TESTING=ON CMake options
1413

1514
Run it:
16-
$ PROJ_DATA=../../data ./standard_fuzzer {file_generated_by_oss_fuzz}
15+
$ bin/proj_crs_to_crs_fuzzer {file_generated_by_oss_fuzz}
1716

1817
- Run locally OSS Fuzz:
1918
$ git clone https://github.com/google/oss-fuzz.git
@@ -24,8 +23,8 @@ https://bugs.chromium.org/p/oss-fuzz/issues/list?q=proj4
2423
Build fuzzers with the address sanitizer (could use undefined, etc...)
2524
$ python infra/helper.py build_fuzzers --sanitizer address $PROJECT_NAME
2625

27-
Test a particular fuzzer (replace standard_fuzzer by other fuzzers)
28-
$ python infra/helper.py run_fuzzer $PROJECT_NAME standard_fuzzer
26+
Test a particular fuzzer (replace proj_crs_to_crs_fuzzer by other fuzzers)
27+
$ python infra/helper.py run_fuzzer $PROJECT_NAME proj_crs_to_crs_fuzzer
2928

3029

3130
How to deal with issues reported in https://bugs.chromium.org/p/oss-fuzz/issues/list?q=proj4 ?

test/fuzzers/proj_crs_to_crs_fuzzer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ int main(int argc, char *argv[]) {
124124
fclose(f);
125125
exit(1);
126126
}
127-
fread(buf, nLen, 1, f);
127+
if (fread(buf, nLen, 1, f) != 1) {
128+
fprintf(stderr, "fread failed.\n");
129+
fclose(f);
130+
free(buf);
131+
exit(1);
132+
}
128133
fclose(f);
129134
nRet = LLVMFuzzerTestOneInput((const uint8_t *)(buf), nLen);
130135
free(buf);

0 commit comments

Comments
 (0)