Skip to content

Commit a9bb1a1

Browse files
committed
Add a fuzzer for parseNumber()
See #2220
1 parent 34888e5 commit a9bb1a1

28 files changed

Lines changed: 42 additions & 2 deletions

extras/fuzzing/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION
6464

6565
add_fuzzer(json)
6666
add_fuzzer(msgpack)
67+
add_fuzzer(number)
6768
endif()

extras/fuzzing/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ all: \
88
$(OUT)/json_fuzzer.options \
99
$(OUT)/msgpack_fuzzer \
1010
$(OUT)/msgpack_fuzzer_seed_corpus.zip \
11-
$(OUT)/msgpack_fuzzer.options
11+
$(OUT)/msgpack_fuzzer.options \
12+
$(OUT)/number_fuzzer \
13+
$(OUT)/number_fuzzer_seed_corpus.zip \
14+
$(OUT)/number_fuzzer.options
1215

1316
$(OUT)/%_fuzzer: %_fuzzer.cpp $(shell find ../../src -type f)
1417
$(CXX) $(CXXFLAGS) $< -o$@ $(LIB_FUZZING_ENGINE)
@@ -18,5 +21,5 @@ $(OUT)/%_fuzzer_seed_corpus.zip: %_seed_corpus/*
1821

1922
$(OUT)/%_fuzzer.options:
2023
@echo "[libfuzzer]" > $@
21-
@echo "max_len = 256" >> $@
24+
@echo "max_len = 4096" >> $@
2225
@echo "timeout = 10" >> $@
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

extras/fuzzing/number_fuzzer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <ArduinoJson.h>
2+
3+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
4+
// Make a copy to ensure the input is null-terminated
5+
std::string str(reinterpret_cast<const char*>(data), size);
6+
7+
ArduinoJson::detail::parseNumber(str.c_str());
8+
9+
return 0;
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
infinity
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
999999.999999

0 commit comments

Comments
 (0)