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 <adam@adalogics.com>
PR-URL: #51088
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
AdamKorcz committed May 12, 2024
1 parent d9b61db commit 65573f4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
43 changes: 43 additions & 0 deletions node.gyp
Expand Up @@ -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',
Expand Down
16 changes: 16 additions & 0 deletions test/fuzzers/fuzz_ClientHelloParser.cc
@@ -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 65573f4

Please sign in to comment.