test: add fuzzer for ClientHelloParser

Signed-off-by: Adam Korczynski <adam@adalogics.com>
PR-URL: https://github.com/nodejs/node/pull/51088
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
AdamKorcz 2024-05-12 18:28:44 +01:00 committed by GitHub
parent d9b61dbe89
commit 65573f4864
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 0 deletions

View File

@ -1066,6 +1066,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',

View File

@ -0,0 +1,16 @@
/*
* A fuzzer focused on node::crypto::ClientHelloParser.
*/
#include <stdlib.h>
#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;
}