Skip to content

Commit 06c5120

Browse files
DavidKorczynskiaddaleax
authored andcommittedSep 22, 2020
build: add build flag for OSS-Fuzz integration
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>
1 parent 9d07217 commit 06c5120

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
 

‎configure.py

+8
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@
381381
dest='v8_options',
382382
help='v8 options to pass, see `node --v8-options` for examples.')
383383

384+
parser.add_option('--with-ossfuzz',
385+
action='store_true',
386+
dest='ossfuzz',
387+
help='Enables building of fuzzers. This command should be run in an OSS-Fuzz Docker image.')
388+
384389
parser.add_option('--with-arm-float-abi',
385390
action='store',
386391
dest='arm_float_abi',
@@ -1718,6 +1723,9 @@ def make_bin_override():
17181723
configure_static(output)
17191724
configure_inspector(output)
17201725

1726+
# Forward OSS-Fuzz settings
1727+
output['variables']['ossfuzz'] = b(options.ossfuzz)
1728+
17211729
# variables should be a root level element,
17221730
# move everything else to target_defaults
17231731
variables = output['variables']

‎node.gyp

+33
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'node_use_bundled_v8%': 'true',
1212
'node_shared%': 'false',
1313
'force_dynamic_crt%': 0,
14+
'ossfuzz' : 'false',
1415
'node_module_version%': '',
1516
'node_shared_brotli%': 'false',
1617
'node_shared_zlib%': 'false',
@@ -1107,6 +1108,38 @@
11071108
} ],
11081109
]
11091110
}, # specialize_node_d
1111+
{ # fuzz_url
1112+
'target_name': 'fuzz_url',
1113+
'type': 'executable',
1114+
'dependencies': [
1115+
'<(node_lib_target_name)',
1116+
],
1117+
'includes': [
1118+
'node.gypi'
1119+
],
1120+
'include_dirs': [
1121+
'src',
1122+
],
1123+
'defines': [
1124+
'NODE_ARCH="<(target_arch)"',
1125+
'NODE_PLATFORM="<(OS)"',
1126+
'NODE_WANT_INTERNALS=1',
1127+
],
1128+
'sources': [
1129+
'src/node_snapshot_stub.cc',
1130+
'src/node_code_cache_stub.cc',
1131+
'test/fuzzers/fuzz_url.cc',
1132+
],
1133+
'conditions': [
1134+
['OS=="linux"', {
1135+
'ldflags': [ '-fsanitize=fuzzer' ]
1136+
}],
1137+
# Ensure that ossfuzz flag has been set and that we are on Linux
1138+
[ 'OS!="linux" or ossfuzz!="true"', {
1139+
'type': 'none',
1140+
}],
1141+
],
1142+
}, # fuzz_url
11101143
{
11111144
'target_name': 'cctest',
11121145
'type': 'executable',

‎test/fuzzers/fuzz_url.cc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdlib.h>
2+
3+
#include "node.h"
4+
#include "node_internals.h"
5+
#include "node_url.h"
6+
7+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
8+
node::url::URL url2(reinterpret_cast<const char*>(data), size);
9+
10+
return 0;
11+
}

0 commit comments

Comments
 (0)
Please sign in to comment.