Skip to content

Commit 375b859

Browse files
DavidKorczynskiTrott
authored andcommitted
build: add build flag for OSS-Fuzz integration
Refs: google/oss-fuzz#3860 Fixes: #33724 PR-URL: #34761 Fixes: #33724 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 5d179cb commit 375b859

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

configure.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@
439439
dest='v8_options',
440440
help='v8 options to pass, see `node --v8-options` for examples.')
441441

442+
parser.add_option('--with-ossfuzz',
443+
action='store_true',
444+
dest='ossfuzz',
445+
help='Enables building of fuzzers. This command should be run in an OSS-Fuzz Docker image.')
446+
442447
parser.add_option('--with-arm-float-abi',
443448
action='store',
444449
dest='arm_float_abi',
@@ -1827,6 +1832,9 @@ def make_bin_override():
18271832
configure_static(output)
18281833
configure_inspector(output)
18291834

1835+
# Forward OSS-Fuzz settings
1836+
output['variables']['ossfuzz'] = b(options.ossfuzz)
1837+
18301838
# variables should be a root level element,
18311839
# move everything else to target_defaults
18321840
variables = output['variables']

node.gyp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'node_use_bundled_v8%': 'true',
1414
'node_shared%': 'false',
1515
'force_dynamic_crt%': 0,
16+
'ossfuzz' : 'false',
1617
'node_module_version%': '',
1718
'node_shared_brotli%': 'false',
1819
'node_shared_zlib%': 'false',
@@ -1170,6 +1171,38 @@
11701171
} ],
11711172
]
11721173
}, # specialize_node_d
1174+
{ # fuzz_url
1175+
'target_name': 'fuzz_url',
1176+
'type': 'executable',
1177+
'dependencies': [
1178+
'<(node_lib_target_name)',
1179+
],
1180+
'includes': [
1181+
'node.gypi'
1182+
],
1183+
'include_dirs': [
1184+
'src',
1185+
],
1186+
'defines': [
1187+
'NODE_ARCH="<(target_arch)"',
1188+
'NODE_PLATFORM="<(OS)"',
1189+
'NODE_WANT_INTERNALS=1',
1190+
],
1191+
'sources': [
1192+
'src/node_snapshot_stub.cc',
1193+
'src/node_code_cache_stub.cc',
1194+
'test/fuzzers/fuzz_url.cc',
1195+
],
1196+
'conditions': [
1197+
['OS=="linux"', {
1198+
'ldflags': [ '-fsanitize=fuzzer' ]
1199+
}],
1200+
# Ensure that ossfuzz flag has been set and that we are on Linux
1201+
[ 'OS!="linux" or ossfuzz!="true"', {
1202+
'type': 'none',
1203+
}],
1204+
],
1205+
}, # fuzz_url
11731206
{
11741207
'target_name': 'cctest',
11751208
'type': 'executable',

test/fuzzers/fuzz_url.cc

Lines changed: 11 additions & 0 deletions
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)