Skip to content

Commit 4c5bd1d

Browse files
[Nodejs] initial integration. (#3860)
* Nodejs initial integration. * Added headers to fix Travis. * A lot of simplifications to build script. LDFLAGS is the key here. * More simplifications to build script. * Fix Travis. * Remove msan. * Generalise and simplify build script. * utilise all cores and a bit nicer structure in build.
1 parent fa9c352 commit 4c5bd1d

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

projects/nodejs/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2020 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
17+
FROM gcr.io/oss-fuzz-base/base-builder
18+
19+
RUN apt-get update && apt-get install -y make
20+
RUN apt-get install -y flex bison build-essential
21+
RUN git clone --recursive --depth 1 https://github.com/nodejs/node
22+
WORKDIR $SRC
23+
COPY build.sh $SRC/
24+
25+
COPY fuzz_url.cc $SRC/

projects/nodejs/build.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash -eu
2+
# Copyright 2020 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
################################################################################
17+
cd $SRC/node
18+
19+
# Build node
20+
export LDFLAGS="$CXXFLAGS"
21+
export LD="$CXX"
22+
./configure --without-intl --without-node-code-cache --without-dtrace --without-snapshot --without-ssl
23+
make -j$(nproc)
24+
25+
# Gather static libraries
26+
cd $SRC/node/out
27+
rm -rf ./library_files && mkdir library_files
28+
find . -name "*.a" -exec cp {} ./library_files/ \;
29+
30+
# Build the fuzzers
31+
CMDS="-D__STDC_FORMAT_MACROS -D__POSIX__ -DNODE_HAVE_I18N_SUPPORT=1 \
32+
-DNODE_ARCH=\"x64\" -DNODE_PLATFORM=\"linux\" -DNODE_WANT_INTERNALS=1"
33+
INCLUDES="-I../src -I../deps/v8/include -I../deps/uv/include"
34+
35+
# Compilation
36+
$CXX -o fuzz_url.o $SRC/fuzz_url.cc $CXXFLAGS $CMDS $INCLUDES \
37+
-pthread -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++1y -MMD -c
38+
39+
# Linking
40+
$CXX -o $OUT/fuzz_url $LIB_FUZZING_ENGINE $CXXFLAGS \
41+
-rdynamic -Wl,-z,noexecstack,-z,relro,-z,now \
42+
-pthread -Wl,--start-group \
43+
./Release/obj.target/cctest/src/node_snapshot_stub.o \
44+
./Release/obj.target/cctest/src/node_code_cache_stub.o \
45+
fuzz_url.o ./library_files/*.a \
46+
-latomic -lm -ldl -Wl,--end-group

projects/nodejs/fuzz_url.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Copyright 2020 Google Inc.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
#include <stdlib.h>
16+
17+
#include "node.h"
18+
#include "node_internals.h"
19+
#include "node_url.h"
20+
21+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
22+
node::url::URL url2((char*)data, size);
23+
24+
return 0;
25+
}

projects/nodejs/project.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
homepage: "https://nodejs.org"
22
primary_contact: "[email protected]"
3+
language: c++
4+
sanitizers:
5+
- address
6+
auto_ccs:
7+

0 commit comments

Comments
 (0)