From f6837d8417bb2864ea120ef460e9eff69475e94b Mon Sep 17 00:00:00 2001 From: davkor Date: Thu, 13 Aug 2020 17:12:44 +0100 Subject: [PATCH 1/5] Added setup for OSS-Fuzz integration. --- configure.py | 8 ++++++ node.gyp | 56 ++++++++++++++++++++++++++++++++++++++++ test/fuzzers/fuzz_url.cc | 11 ++++++++ 3 files changed, 75 insertions(+) create mode 100644 test/fuzzers/fuzz_url.cc diff --git a/configure.py b/configure.py index fc702ce06fbbaf..789d25afa4ef3c 100755 --- a/configure.py +++ b/configure.py @@ -439,6 +439,11 @@ dest='v8_options', help='v8 options to pass, see `node --v8-options` for examples.') +parser.add_option('--with-ossfuzz', + action='store_true', + default=False, + dest='ossfuzz') + parser.add_option('--with-arm-float-abi', action='store', dest='arm_float_abi', @@ -1827,6 +1832,9 @@ def make_bin_override(): configure_static(output) configure_inspector(output) +# Forward OSS-Fuzz settings +output['variables']['ossfuzz'] = b(options.ossfuzz) + # variables should be a root level element, # move everything else to target_defaults variables = output['variables'] diff --git a/node.gyp b/node.gyp index 72e06754210cc4..1ea66fd627ed4f 100644 --- a/node.gyp +++ b/node.gyp @@ -13,6 +13,7 @@ 'node_use_bundled_v8%': 'true', 'node_shared%': 'false', 'force_dynamic_crt%': 0, + 'ossfuzz' : 'true', 'node_module_version%': '', 'node_shared_brotli%': 'false', 'node_shared_zlib%': 'false', @@ -1169,6 +1170,61 @@ } ], ] }, # specialize_node_d + { # fuzz_url + 'target_name': 'fuzz_url', + 'type': 'executable', + + 'dependencies': [ + '<(node_lib_target_name)', + 'deps/histogram/histogram.gyp:histogram', + 'deps/uvwasi/uvwasi.gyp:uvwasi', + 'node_dtrace_header', + 'node_dtrace_ustack', + 'node_dtrace_provider', + ], + + 'includes': [ + 'node.gypi' + ], + + 'include_dirs': [ + 'src', + 'tools/msvs/genfiles', + 'deps/v8/include', + 'deps/cares/include', + 'deps/uv/include', + 'deps/uvwasi/include', + ], + + 'defines': [ + 'NODE_ARCH="<(target_arch)"', + 'NODE_PLATFORM="<(OS)"', + 'NODE_WANT_INTERNALS=1', + ], + + 'sources': [ + 'src/node_snapshot_stub.cc', + 'src/node_code_cache_stub.cc', + 'test/fuzzers/fuzz_url.cc', + ], + + 'conditions': [ + [ 'node_use_openssl=="true"', { + 'defines': [ + 'HAVE_OPENSSL=1', + ], + }], + ['OS=="linux"', { + 'ldflags': [ '-fsanitize=fuzzer' ] + }], + # Skip cctest while building shared lib node for Windows + [ 'OS!="linux" or ossfuzz!="true"', { + 'type': 'none', + }], + ], + }, # fuzz_url + + { 'target_name': 'cctest', 'type': 'executable', diff --git a/test/fuzzers/fuzz_url.cc b/test/fuzzers/fuzz_url.cc new file mode 100644 index 00000000000000..8083138b88214d --- /dev/null +++ b/test/fuzzers/fuzz_url.cc @@ -0,0 +1,11 @@ +#include + +#include "node.h" +#include "node_internals.h" +#include "node_url.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + node::url::URL url2((char*)data, size); + + return 0; +} From 10647c0abfc5f39dbd4efb8c8fa68df2040eae84 Mon Sep 17 00:00:00 2001 From: davkor Date: Thu, 13 Aug 2020 17:53:18 +0100 Subject: [PATCH 2/5] Simplified the gyp settings for fuzz-url. --- node.gyp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/node.gyp b/node.gyp index 1ea66fd627ed4f..d1d94251b06d5e 100644 --- a/node.gyp +++ b/node.gyp @@ -1176,11 +1176,6 @@ 'dependencies': [ '<(node_lib_target_name)', - 'deps/histogram/histogram.gyp:histogram', - 'deps/uvwasi/uvwasi.gyp:uvwasi', - 'node_dtrace_header', - 'node_dtrace_ustack', - 'node_dtrace_provider', ], 'includes': [ @@ -1189,11 +1184,6 @@ 'include_dirs': [ 'src', - 'tools/msvs/genfiles', - 'deps/v8/include', - 'deps/cares/include', - 'deps/uv/include', - 'deps/uvwasi/include', ], 'defines': [ @@ -1209,15 +1199,10 @@ ], 'conditions': [ - [ 'node_use_openssl=="true"', { - 'defines': [ - 'HAVE_OPENSSL=1', - ], - }], ['OS=="linux"', { 'ldflags': [ '-fsanitize=fuzzer' ] }], - # Skip cctest while building shared lib node for Windows + # Ensure that ossfuzz flag has been set and that we are on Linux [ 'OS!="linux" or ossfuzz!="true"', { 'type': 'none', }], From ba5b7df02dd22708825900ff6684570e11539547 Mon Sep 17 00:00:00 2001 From: davkor Date: Thu, 13 Aug 2020 18:01:51 +0100 Subject: [PATCH 3/5] Removed whitespace. --- node.gyp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/node.gyp b/node.gyp index d1d94251b06d5e..22e59cd0bd59dc 100644 --- a/node.gyp +++ b/node.gyp @@ -1173,31 +1173,25 @@ { # fuzz_url 'target_name': 'fuzz_url', 'type': 'executable', - 'dependencies': [ '<(node_lib_target_name)', ], - 'includes': [ 'node.gypi' ], - 'include_dirs': [ 'src', ], - 'defines': [ 'NODE_ARCH="<(target_arch)"', 'NODE_PLATFORM="<(OS)"', 'NODE_WANT_INTERNALS=1', ], - 'sources': [ 'src/node_snapshot_stub.cc', 'src/node_code_cache_stub.cc', 'test/fuzzers/fuzz_url.cc', ], - 'conditions': [ ['OS=="linux"', { 'ldflags': [ '-fsanitize=fuzzer' ] @@ -1208,8 +1202,6 @@ }], ], }, # fuzz_url - - { 'target_name': 'cctest', 'type': 'executable', From fdace7ef1e1d8663f1e5e983e2fe9caa95213b49 Mon Sep 17 00:00:00 2001 From: davkor Date: Thu, 13 Aug 2020 20:01:36 +0100 Subject: [PATCH 4/5] Added a help description for the with-ossfuzz configuration. --- configure.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure.py b/configure.py index 789d25afa4ef3c..6cc18d351e0ab7 100755 --- a/configure.py +++ b/configure.py @@ -442,7 +442,8 @@ parser.add_option('--with-ossfuzz', action='store_true', default=False, - dest='ossfuzz') + dest='ossfuzz', + help='Enables building of fuzzers. This command should be run in an OSS-Fuzz Docker image.') parser.add_option('--with-arm-float-abi', action='store', From fd987b66ed783f78aff1785eecfc1b0b1d92075f Mon Sep 17 00:00:00 2001 From: davkor Date: Thu, 13 Aug 2020 22:06:47 +0100 Subject: [PATCH 5/5] Resolved suggestions for improvements in oss-fuzz infrastructure. --- configure.py | 1 - node.gyp | 2 +- test/fuzzers/fuzz_url.cc | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/configure.py b/configure.py index 6cc18d351e0ab7..5134892cb5234a 100755 --- a/configure.py +++ b/configure.py @@ -441,7 +441,6 @@ parser.add_option('--with-ossfuzz', action='store_true', - default=False, dest='ossfuzz', help='Enables building of fuzzers. This command should be run in an OSS-Fuzz Docker image.') diff --git a/node.gyp b/node.gyp index 22e59cd0bd59dc..5da3ae61bcba14 100644 --- a/node.gyp +++ b/node.gyp @@ -13,7 +13,7 @@ 'node_use_bundled_v8%': 'true', 'node_shared%': 'false', 'force_dynamic_crt%': 0, - 'ossfuzz' : 'true', + 'ossfuzz' : 'false', 'node_module_version%': '', 'node_shared_brotli%': 'false', 'node_shared_zlib%': 'false', diff --git a/test/fuzzers/fuzz_url.cc b/test/fuzzers/fuzz_url.cc index 8083138b88214d..16c5f644893f86 100644 --- a/test/fuzzers/fuzz_url.cc +++ b/test/fuzzers/fuzz_url.cc @@ -5,7 +5,7 @@ #include "node_url.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - node::url::URL url2((char*)data, size); + node::url::URL url2(reinterpret_cast(data), size); return 0; }