Skip to content

Commit

Permalink
oss-fuzz: Port the test suite script from google/oss-fuzz
Browse files Browse the repository at this point in the history
This allows us to more easily manage oss-fuzz failures on OpenSIPS
project side, without requiring an oss-fuzz PR on each build or
test-related change.
  • Loading branch information
liviuchircu committed Sep 9, 2022
1 parent 2226238 commit f988e15
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ endif
ifeq (1,$(shell grep -c '^\DEFS+= -DUNIT_TESTS' $(TOP_SRCDIR)/Makefile.conf))
DEFS := $(DEFS) -DUNIT_TESTS
LIBS := $(LIBS) -ltap
test_src := $(shell find . -wholename "*/test/*\.c" | grep -v "^./modules/")
test_src := $(shell find . -wholename "*/test/*\.c" | grep -vE "^./(modules|test/fuzz)/")
test_objs := $(test_src:.c=.o)
objs := $(objs) $(test_objs)
endif
Expand Down
45 changes: 45 additions & 0 deletions test/fuzz/oss-fuzz-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash -eu
# Copyright 2022 OpenSIPS Solutions
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

# disable all custom memory allocators, use system malloc instead
sed -i '
s/^#\?\(DEFS+= -DPKG_MALLOC\)/DEFS+= -DSYSTEM_MALLOC/g
s/^\(DEFS+= -DUSE_MCAST\)/#\1/g
s/^\(DEFS+= -DF_MALLOC\)/#\1/g
s/^\(DEFS+= -DQ_MALLOC\)/#\1/g
s/^\(DEFS+= -DHP_MALLOC\)/#\1/g
s/^\(DEFS+= -DDBG_MALLOC\)/#\1/g
s/^\(DEFS+= -DDBG_MALLOC\)/#\1/g
s/^#\(DEFS+= -DFUZZ_BUILD\)/\1/g
' Makefile.conf.template

# disable update_stat() calls in the parser, since they rely on SHM
sed -i '/update_stat.*bad_URIs/d' parser/parse_uri.c
sed -i '/update_stat.*bad_msg_hdr/d' parser/msg_parser.c

cp ./test/fuzz/fuzz_*.c ./parser/

make static

rm main.o
mkdir objects && find . -name "*.o" -exec cp {} ./objects/ \;
ar -r libopensips.a ./objects/*.o

$CC $CFLAGS $LIB_FUZZING_ENGINE ./parser/fuzz_msg_parser.o ./libopensips.a -ldl -lresolv -o $OUT/fuzz_msg_parser
$CC $CFLAGS $LIB_FUZZING_ENGINE ./parser/fuzz_uri_parser.o ./libopensips.a -ldl -lresolv -o $OUT/fuzz_uri_parser
$CC $CFLAGS $LIB_FUZZING_ENGINE ./parser/fuzz_csv_parser.o ./libopensips.a -ldl -lresolv -o $OUT/fuzz_csv_parser

0 comments on commit f988e15

Please sign in to comment.