Skip to content

Commit

Permalink
test: add fuzzer for ClientHelloParser
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <[email protected]>
PR-URL: #51088
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
AdamKorcz authored and marco-ippolito committed Jun 17, 2024
1 parent cc74bf7 commit 5fb829b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
43 changes: 43 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,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',
Expand Down
16 changes: 16 additions & 0 deletions test/fuzzers/fuzz_ClientHelloParser.cc
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 5fb829b

Please sign in to comment.