From 6da758b7d09e9153b7b8e05da04ea8f43142ad43 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Thu, 2 Apr 2026 10:41:04 -0700 Subject: [PATCH] oss-fuzz: add new sdp parser fuzzer The goal is to increase the code coverage by way of OSS-Fuzz. Latest coverage report of sdp is availableh here: https://storage.googleapis.com/oss-fuzz-coverage/opensips/reports/20260331/linux/src/opensips/parser/sdp/report.html Signed-off-by: David Korczynski --- test/fuzz/fuzz_sdp_parser.c | 51 +++++++++++++++++++++++++++++++++++++ test/fuzz/oss-fuzz-build.sh | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/fuzz/fuzz_sdp_parser.c diff --git a/test/fuzz/fuzz_sdp_parser.c b/test/fuzz/fuzz_sdp_parser.c new file mode 100644 index 00000000000..f31a9467a5c --- /dev/null +++ b/test/fuzz/fuzz_sdp_parser.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2026 OpenSIPS Solutions + * + * This file is part of opensips, a free SIP server. + * + * opensips is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * opensips is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA + */ + +#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" + +#include "../test/fuzz/fuzz_standalone.h" + +int LLVMFuzzerTestOneInput(const char *data, size_t size) { + if (size <= 1) { + return 0; + } + + str sdp_body = { (char*)data, (int)size }; + sdp_info_t* sdp = new_sdp(); + if (sdp) { + str cnt_disp = {NULL, 0}; + parse_sdp_session(&sdp_body, 0, &cnt_disp, sdp); + free_sdp(sdp); + } + + return 0; +} diff --git a/test/fuzz/oss-fuzz-build.sh b/test/fuzz/oss-fuzz-build.sh index 9c79a876121..a61d889132a 100755 --- a/test/fuzz/oss-fuzz-build.sh +++ b/test/fuzz/oss-fuzz-build.sh @@ -52,7 +52,7 @@ ${MAKE} static rm -f main.o libopensips.a ar -cr libopensips.a `find . -name "*.o" | grep -v '/fuzz_.*.o$'` -for fuzn in msg_parser uri_parser csv_parser core_funcs +for fuzn in msg_parser uri_parser csv_parser core_funcs sdp_parser do $CC $CFLAGS $LIB_FUZZING_ENGINE ./parser/fuzz_${fuzn}.o libopensips.a ${LIBS} -o $OUT/fuzz_${fuzn} if [ -e test/fuzz/fuzz_${fuzn}.dict ]