Skip to content

Commit

Permalink
build: add build flag for OSS-Fuzz integration
Browse files Browse the repository at this point in the history
Refs: google/oss-fuzz#3860
Fixes: #33724

PR-URL: #34761
Fixes: #33724
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
DavidKorczynski authored and Trott committed Aug 15, 2020
1 parent 5d179cb commit 375b859
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
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',
dest='arm_float_abi',
Expand Down Expand Up @@ -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']
Expand Down
33 changes: 33 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'node_use_bundled_v8%': 'true',
'node_shared%': 'false',
'force_dynamic_crt%': 0,
'ossfuzz' : 'false',
'node_module_version%': '',
'node_shared_brotli%': 'false',
'node_shared_zlib%': 'false',
Expand Down Expand Up @@ -1170,6 +1171,38 @@
} ],
]
}, # specialize_node_d
{ # 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' ]
}],
# Ensure that ossfuzz flag has been set and that we are on Linux
[ 'OS!="linux" or ossfuzz!="true"', {
'type': 'none',
}],
],
}, # fuzz_url
{
'target_name': 'cctest',
'type': 'executable',
Expand Down
11 changes: 11 additions & 0 deletions test/fuzzers/fuzz_url.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdlib.h>

#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(reinterpret_cast<const char*>(data), size);

return 0;
}

0 comments on commit 375b859

Please sign in to comment.