diff options
author | DavidKorczynski <david@adalogics.com> | 2021-10-08 16:27:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-08 11:27:27 -0400 |
commit | 0b04d48432b998667b73a2f54fbc9347100790ee (patch) | |
tree | abc31e119ed82cbd333f65bcdc392f087443d3db | |
parent | acc4ead138086482bb9c30a09bd682221c4e9cab (diff) | |
download | oss-fuzz-0b04d48432b998667b73a2f54fbc9347100790ee.tar.gz |
opensips: initial integration. (#6420)
* opensips: initial integration.
* opensips: include primary contact
-rwxr-xr-x | projects/opensips/Dockerfile | 25 | ||||
-rwxr-xr-x | projects/opensips/build.sh | 27 | ||||
-rw-r--r-- | projects/opensips/fuzz_msg_parser.c | 41 | ||||
-rw-r--r-- | projects/opensips/fuzz_uri_parser.c | 40 | ||||
-rw-r--r-- | projects/opensips/patch.diff | 57 | ||||
-rwxr-xr-x | projects/opensips/project.yaml | 6 |
6 files changed, 196 insertions, 0 deletions
diff --git a/projects/opensips/Dockerfile b/projects/opensips/Dockerfile new file mode 100755 index 000000000..c7b364a42 --- /dev/null +++ b/projects/opensips/Dockerfile @@ -0,0 +1,25 @@ +# 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. +# +################################################################################ + +FROM gcr.io/oss-fuzz-base/base-builder +RUN apt-get update && apt-get install -y bison flex libssl-dev pkg-config +RUN git clone https://github.com/OpenSIPS/opensips + +COPY patch.diff $SRC/ +COPY build.sh $SRC/ +COPY fuzz_*.c $SRC/opensips/parser/ + +WORKDIR opensips diff --git a/projects/opensips/build.sh b/projects/opensips/build.sh new file mode 100755 index 000000000..9aeb9cd0f --- /dev/null +++ b/projects/opensips/build.sh @@ -0,0 +1,27 @@ +#!/bin/bash -eu +# 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. +# +################################################################################ + +git apply --ignore-space-change --ignore-whitespace $SRC/patch.diff + +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 diff --git a/projects/opensips/fuzz_msg_parser.c b/projects/opensips/fuzz_msg_parser.c new file mode 100644 index 000000000..4daec4266 --- /dev/null +++ b/projects/opensips/fuzz_msg_parser.c @@ -0,0 +1,41 @@ +/* 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. +*/ +#include "../parser/sdp/sdp.h" + +#include "../cachedb/test/test_cachedb.h" +#include "../lib/test/test_csv.h" +#include "../mem/test/test_malloc.h" +#include "../str.h" + +#include "../context.h" +#include "../dprint.h" +#include "../globals.h" +#include "../lib/list.h" +#include "../sr_module.h" +#include "../sr_module_deps.h" + +int LLVMFuzzerTestOneInput(const char *data, size_t size) { + ensure_global_context(); + struct sip_uri u; + + if (size <= 1) { + return 0; + } + + struct sip_msg orig_inv = {}; + orig_inv.buf = (char *)data; + orig_inv.len = size; + + parse_msg(orig_inv.buf, orig_inv.len, &orig_inv); + free_sip_msg(&orig_inv); + return 0; +} diff --git a/projects/opensips/fuzz_uri_parser.c b/projects/opensips/fuzz_uri_parser.c new file mode 100644 index 000000000..1a1647458 --- /dev/null +++ b/projects/opensips/fuzz_uri_parser.c @@ -0,0 +1,40 @@ +/* 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. +*/ +#include "../cachedb/test/test_cachedb.h" +#include "../lib/test/test_csv.h" +#include "../mem/test/test_malloc.h" +#include "../str.h" + +#include "../context.h" +#include "../dprint.h" +#include "../globals.h" +#include "../lib/list.h" +#include "../sr_module.h" +#include "../sr_module_deps.h" + +#include "parse_uri.h" + +int LLVMFuzzerTestOneInput(const char *data, size_t size) { + ensure_global_context(); + struct sip_uri u; + + char *new_str = (char *)malloc(size + 1); + if (new_str == NULL) { + return 0; + } + memcpy(new_str, data, size); + new_str[size] = '\0'; + + parse_uri(STR_L(new_str), &u); + + free(new_str); +} diff --git a/projects/opensips/patch.diff b/projects/opensips/patch.diff new file mode 100644 index 000000000..a382129ed --- /dev/null +++ b/projects/opensips/patch.diff @@ -0,0 +1,57 @@ +diff --git a/Makefile.conf.template b/Makefile.conf.template +index 5a76e0a35..2570db165 100644 +--- a/Makefile.conf.template ++++ b/Makefile.conf.template +@@ -69,17 +69,19 @@ exclude_modules?= aaa_diameter aaa_radius auth_jwt b2b_logic_xml cachedb_cassand + + include_modules?= + +-DEFS+= -DPKG_MALLOC #Use a faster malloc +-DEFS+= -DSHM_MMAP #Use mmap instead of SYSV shared memory +-DEFS+= -DUSE_MCAST #Compile in support for IP Multicast ++#DEFS+= -DPKG_MALLOC #Use a faster malloc ++#DEFS+= -DSHM_MMAP #Use mmap instead of SYSV shared memory ++#DEFS+= -DUSE_MCAST #Compile in support for IP Multicast + DEFS+= -DDISABLE_NAGLE #Disable the TCP NAgle Algorithm ( lower delay ) + DEFS+= -DSTATISTICS #Enable the statistics manager ++DEFS+= -DSYSTEM_MALLOC ++DEFS+= -DSHM_MMAP + DEFS+= -DHAVE_RESOLV_RES #Support for changing some of the resolver parameters + # Specifying exactly 1 allocator will cause it to be inlined (fastest) +-DEFS+= -DF_MALLOC #Fast memory allocator with minimal runtime overhead +-DEFS+= -DQ_MALLOC #Quality assurance memory allocator with runtime safety checks +-DEFS+= -DHP_MALLOC #High performance allocator with fine-grained locking +-DEFS+= -DDBG_MALLOC #Include additional, debug-enabled allocator flavors ++#DEFS+= -DF_MALLOC #Fast memory allocator with minimal runtime overhead ++#DEFS+= -DQ_MALLOC #Quality assurance memory allocator with runtime safety checks ++#DEFS+= -DHP_MALLOC #High performance allocator with fine-grained locking ++#DEFS+= -DDBG_MALLOC #Include additional, debug-enabled allocator flavors + #DEFS+= -DNO_DEBUG #Compile out all debug messages + #DEFS+= -DNO_LOG #Compile out all logging + #DEFS_GROUP_START +diff --git a/parser/msg_parser.c b/parser/msg_parser.c +index db09aff7f..99ea58435 100644 +--- a/parser/msg_parser.c ++++ b/parser/msg_parser.c +@@ -263,7 +263,7 @@ error_bad_hdr: + set_err_reply(400, "bad headers"); + error: + LM_DBG("error exit\n"); +- update_stat( bad_msg_hdr, 1); ++ //update_stat( bad_msg_hdr, 1); + hdr->type=HDR_ERROR_T; + hdr->len=tmp-hdr->name.s; + return tmp; +diff --git a/parser/parse_uri.c b/parser/parse_uri.c +index 364d91c1f..2f1ff1130 100644 +--- a/parser/parse_uri.c ++++ b/parser/parse_uri.c +@@ -1628,7 +1628,7 @@ error_bug: + error_exit: + ser_error=E_BAD_URI; + uri->type=ERROR_URI_T; +- update_stat(bad_URIs, 1); ++ //update_stat(bad_URIs, 1); + return E_BAD_URI; + } + diff --git a/projects/opensips/project.yaml b/projects/opensips/project.yaml new file mode 100755 index 000000000..ff7091745 --- /dev/null +++ b/projects/opensips/project.yaml @@ -0,0 +1,6 @@ +homepage: "https://opensips.org/" +main_repo: "https://github.com/OpenSIPS/opensips" +primary_contact: "liviu@opensips.org" +language: c +auto_ccs: + - "david@adalogics.com" |