From 5f6415b41d29ac8460eca1df3ed6280c5ec1a47e Mon Sep 17 00:00:00 2001 From: AdamKorcz <44787359+AdamKorcz@users.noreply.github.com> Date: Sun, 12 May 2024 18:28:44 +0100 Subject: [PATCH] test: add fuzzer for `ClientHelloParser` Signed-off-by: Adam Korczynski PR-URL: https://github.com/nodejs/node/pull/51088 Reviewed-By: James M Snell --- node.gyp | 43 ++++++++++++++++++++++++++ test/fuzzers/fuzz_ClientHelloParser.cc | 16 ++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test/fuzzers/fuzz_ClientHelloParser.cc diff --git a/node.gyp b/node.gyp index c7f34f5938fc9a..3e86a830b16bba 100644 --- a/node.gyp +++ b/node.gyp @@ -1067,6 +1067,49 @@ }], ], }, # fuzz_env + { # fuzz_ClientHelloParser.cc + 'target_name': 'fuzz_ClientHelloParser', + 'type': 'executable', + 'dependencies': [ + '<(node_lib_target_name)', + 'deps/histogram/histogram.gyp:histogram', + 'deps/uvwasi/uvwasi.gyp:uvwasi', + ], + 'includes': [ + 'node.gypi' + ], + 'include_dirs': [ + 'src', + 'tools/msvs/genfiles', + 'deps/v8/include', + 'deps/cares/include', + 'deps/uv/include', + 'deps/uvwasi/include', + 'test/cctest', + ], + 'defines': [ + 'NODE_ARCH="<(target_arch)"', + 'NODE_PLATFORM="<(OS)"', + 'NODE_WANT_INTERNALS=1', + ], + 'sources': [ + 'src/node_snapshot_stub.cc', + 'test/fuzzers/fuzz_ClientHelloParser.cc', + ], + 'conditions': [ + ['OS=="linux"', { + 'ldflags': [ '-fsanitize=fuzzer' ] + }], + # Ensure that ossfuzz flag has been set and that we are on Linux + [ 'OS!="linux" or ossfuzz!="true"', { + 'type': 'none', + }], + # Avoid excessive LTO + ['enable_lto=="true"', { + 'ldflags': [ '-fno-lto' ], + }], + ], + }, # fuzz_ClientHelloParser.cc { 'target_name': 'cctest', 'type': 'executable', diff --git a/test/fuzzers/fuzz_ClientHelloParser.cc b/test/fuzzers/fuzz_ClientHelloParser.cc new file mode 100644 index 00000000000000..87d7ae5e303e17 --- /dev/null +++ b/test/fuzzers/fuzz_ClientHelloParser.cc @@ -0,0 +1,16 @@ +/* + * A fuzzer focused on node::crypto::ClientHelloParser. + */ + +#include +#include "crypto/crypto_clienthello-inl.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + node::crypto::ClientHelloParser parser; + bool end_cb_called = false; + parser.Start([](void* arg, auto hello) { }, + [](void* arg) { }, + &end_cb_called); + parser.Parse(data, size); + return 0; +}