From 30cd9d62bea1bd288aecfacc5c7dd8f7e9173951 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Tue, 10 Nov 2026 08:57:32 +0000 Subject: [PATCH 1/4] OSS-Fuzz: Add new fuzzer/corpus/dict targets config handling Signed-off-by: Arthur Chan --- .../seed_modules_default_path.conf | 7 ++ .../config_fuzzer_seeds/seed_modules_dso.conf | 12 +++ .../seed_unknown_keys.conf | 11 +++ scripts/fuzz/fuzz_config_file.c | 93 +++++++++++++++++++ scripts/fuzz/fuzz_config_file.dict | 54 +++++++++++ scripts/fuzz/oss-fuzz-build.sh | 25 ++++- 6 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 scripts/fuzz/config_fuzzer_seeds/seed_modules_default_path.conf create mode 100644 scripts/fuzz/config_fuzzer_seeds/seed_modules_dso.conf create mode 100644 scripts/fuzz/config_fuzzer_seeds/seed_unknown_keys.conf create mode 100644 scripts/fuzz/fuzz_config_file.c create mode 100644 scripts/fuzz/fuzz_config_file.dict diff --git a/scripts/fuzz/config_fuzzer_seeds/seed_modules_default_path.conf b/scripts/fuzz/config_fuzzer_seeds/seed_modules_default_path.conf new file mode 100644 index 000000000..07af63d7a --- /dev/null +++ b/scripts/fuzz/config_fuzzer_seeds/seed_modules_default_path.conf @@ -0,0 +1,7 @@ +modules { + ice_lite { + } + catch_dtmf { + load = 42 + } +} diff --git a/scripts/fuzz/config_fuzzer_seeds/seed_modules_dso.conf b/scripts/fuzz/config_fuzzer_seeds/seed_modules_dso.conf new file mode 100644 index 000000000..43a9ed3ef --- /dev/null +++ b/scripts/fuzz/config_fuzzer_seeds/seed_modules_dso.conf @@ -0,0 +1,12 @@ +modules { + acct_rtcp_hep { + load = ./rtpp_acct_rtcp_hep.so + capt_host = "127.0.0.1" + capt_port = 9060 + capt_ptype = udp + capt_id = 101 + } + acct_csv { + load = ./rtpp_acct_csv.so + } +} diff --git a/scripts/fuzz/config_fuzzer_seeds/seed_unknown_keys.conf b/scripts/fuzz/config_fuzzer_seeds/seed_unknown_keys.conf new file mode 100644 index 000000000..3832863dd --- /dev/null +++ b/scripts/fuzz/config_fuzzer_seeds/seed_unknown_keys.conf @@ -0,0 +1,11 @@ +top_unknown = [1, 2, "three"] +modules { + acct_csv { + load = ./rtpp_acct_csv.so + bogus_key = "x" + } + weird { + load = /nonexistent/lib.so + nested = { a = b } + } +} diff --git a/scripts/fuzz/fuzz_config_file.c b/scripts/fuzz/fuzz_config_file.c new file mode 100644 index 000000000..96da58875 --- /dev/null +++ b/scripts/fuzz/fuzz_config_file.c @@ -0,0 +1,93 @@ +/* + * Fuzzer for rtpproxy configuration file processing. + * + * Feeds fuzzed bytes as a configuration file (UCL format) into + * rtpp_cfile_process(), the entry point rtpproxy main() uses for -c config + * files. This exercises: + * - src/rtpp_cfile.c: file reading, UCL parse orchestration, module + * section dispatch; + * - src/rtpp_ucl.c: rtpproxy's UCL helper wrappers and unknown-key + * handling; + * - external/libucl: the bundled UCL parser/emitter/schema/msgpack code, + * which no other fuzz target reaches (0% covered as of 2026-11-09); + * - module configuration loading: with a "load" parameter pointing at a + * module DSO the build ships next to the fuzzers (the build copies + * every module DSO from modules/MOD/.libs into $OUT), the harness + * drives rtpp_module_if_ctor() (dlopen), module load() and the + * per-module configuration key parsers (e.g. acct_rtcp_hep capt_* keys + * in rtpp_arh_conf.c). + * + * Threat model: the configuration file is the trust boundary for + * librtpproxy API consumers and for anyone provisioning rtpproxy config; + * UCL is a structured text format whose parser (here a bundled copy) is a + * classic memory-safety target. Config-specified module "load" paths go + * through realpath() + dlopen(): path handling on attacker-chosen strings + * is in scope; DSOs that do not exist simply fail cleanly, and only DSOs + * shipped by this same build can ever be loaded inside the OSS-Fuzz + * environment. + * + * Known growth vector: each successfully loaded module instance stays + * registered in the daemon config (by design); once the process runs out + * of file descriptors the module socket setup fails cleanly and parsing + * continues, so the fuzzer degrades to parser-only fuzzing instead of + * crashing or hanging. + */ + +#include +#include +#include +#include +#include +#include + +#include "fuzz_standalone.h" +#include "rfz_utils.h" + +#define HAVE_CONFIG_H 1 +#include "config_pp.h" + +#include "rtpp_cfg.h" +#include "rtpp_cfile.h" + +static char cfgpath[PATH_MAX + 1]; + +int +LLVMFuzzerInitialize(int *_argc, char ***_argv) +{ + + if (RTPPInitialize() != 0) + return (-1); + /* + * Work in $OUT (falling back to /tmp) so that seed corpora using + * relative "load" paths resolve next to the fuzzer binaries, where + * the build ships the module DSOs. + */ + const char *outp = getenv("OUT"); + if (outp != NULL && chdir(outp) != 0) + chdir("/tmp"); + return (0); +} + +int +LLVMFuzzerTestOneInput(const char *data, size_t size) +{ + const char *saved_cfile; + FILE *fp; + + if (size < 2 || size > 65536) + return (0); + + snprintf(cfgpath, sizeof(cfgpath), "/tmp/rfz_cfg_%ld.ucl", (long)getpid()); + fp = fopen(cfgpath, "wb"); + assert(fp != NULL); + assert(fwrite(data, 1, size, fp) == size); + fclose(fp); + + saved_cfile = gconf.cfsp->cfile; + gconf.cfsp->cfile = cfgpath; + rtpp_cfile_process(gconf.cfsp); + gconf.cfsp->cfile = saved_cfile; + + unlink(cfgpath); + return (0); +} diff --git a/scripts/fuzz/fuzz_config_file.dict b/scripts/fuzz/fuzz_config_file.dict new file mode 100644 index 000000000..db7636ee5 --- /dev/null +++ b/scripts/fuzz/fuzz_config_file.dict @@ -0,0 +1,54 @@ +# AFL/libFuzzer dictionary for the rtpproxy configuration file fuzzer. +# UCL syntax tokens plus the rtpproxy module-configuration keys. +# +# UCL structural tokens +brace_open="{" +brace_close="}" +bracket_open="[" +bracket_close="]" +equals="=" +colon=":" +comma="," +dquote="\"" +squote="'" +comment_cpp="//" +comment_c_open="/*" +comment_c_close="*/" +comment_hash="#" +backslash_esc="\\u0001" +macro_include=".include" +macro_path=".path" +macro_priority=".priority" +# UCL value tokens +true="true" +false="false" +null="null" +int_dec="42" +int_neg="-20" +int_hex="0x1f" +int_exp="1e10" +float_pi="3.14159" +big_num="12345678901234567890" +# rtpproxy config keys and module names +modules="modules" +load="load" +mod_acct_csv="acct_csv" +mod_acct_rtcp_hep="acct_rtcp_hep" +mod_catch_dtmf="catch_dtmf" +mod_dtls_gw="dtls_gw" +mod_ice_lite="ice_lite" +capt_host="capt_host" +capt_port="capt_port" +capt_ptype="capt_ptype" +capt_id="capt_id" +proto_udp="udp" +proto_tcp="tcp" +localhost="127.0.0.1" +port_9060="9060" +id_101="101" +dso_hep="./rtpp_acct_rtcp_hep.so" +dso_csv="./rtpp_acct_csv.so" +dso_hep_libs=".libs/rtpp_acct_rtcp_hep.so" +placeholder_topdir="@TOP_BUILDDIR@" +placeholder_hepport="@HEP_PORT@" +placeholder_hepproto="@HEP_PROTO@" diff --git a/scripts/fuzz/oss-fuzz-build.sh b/scripts/fuzz/oss-fuzz-build.sh index 353b1eee3..347b760c6 100755 --- a/scripts/fuzz/oss-fuzz-build.sh +++ b/scripts/fuzz/oss-fuzz-build.sh @@ -116,7 +116,7 @@ do OBJS="${OBJS} ${obj}" done -ALL="command_parser rtp_parser rtcp_parser rtp_session" +ALL="command_parser rtp_parser rtcp_parser rtp_session config_file" OBJS0="${OBJS}" for fz in ${ALL} do @@ -145,6 +145,29 @@ do fi done done + +# fuzz_config_file support: ship the module DSOs next to the fuzzers so that +# seed corpora with relative "load" paths can exercise the module +# configuration loading paths (dlopen + module conf parsing), and pack the +# seed corpus from the existing UCL test fixtures plus the fuzzer-specific +# seeds. +if [ -e modules/Makefile -a -d scripts/fuzz/config_fuzzer_seeds ] +then + for mod in acct_csv acct_rtcp_hep ice_lite catch_dtmf + do + if [ -e modules/${mod}/.libs/rtpp_${mod}.so ] + then + cp -p modules/${mod}/.libs/rtpp_${mod}.so ${OUT}/ + fi + done + SEEDTMP="`mktemp -d ${OUT}/cfg_seed_corpus.XXXXXXXX`" + cp tests/acct_rtcp_hep/*.conf tests/forwarding/rtpproxy.conf \ + tests/libucl/libucl_test*.conf scripts/fuzz/config_fuzzer_seeds/*.conf \ + "${SEEDTMP}/" + (cd "${SEEDTMP}" && zip -q -r "${OUT}/fuzz_config_file_seed_corpus.zip" .) + rm -rf "${SEEDTMP}" +fi + if [ "${OUT}" != "." ] then cp -Rp ${OUT} build-out From 042c5258a3289f90a9188713e7835e48a5daf75c Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Sat, 14 Nov 2026 22:20:39 -0700 Subject: [PATCH 2/4] rtpp_cfile: don't dereference NULL keys from non-object config nodes ucl_object_key() returns NULL for elements that are not members of an object, e.g. when the config root or the "modules" section is an array. rtpp_cfile_process(), parse_modules() and conf_helper_mapper() passed that NULL straight into strcasecmp(), crashing the new fuzz_config_file target (CIFuzz address/undefined/memory: SEGV in strcasecmp at rtpp_cfile.c:116, reproducer: "[1,2]"). Require the config root, the "modules" section and each module section to be objects, and guard against NULL keys. --- src/rtpp_cfile.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/rtpp_cfile.c b/src/rtpp_cfile.c index e6a6e9ad8..cd9cdf8c4 100644 --- a/src/rtpp_cfile.c +++ b/src/rtpp_cfile.c @@ -103,6 +103,11 @@ rtpp_cfile_process(const struct rtpp_cfg *csp) ecode = -1; goto e3; } + if (ucl_object_type(conf_root) != UCL_OBJECT) { + RTPP_LOG(csp->glog, RTPP_LOG_ERR, "Config root must be an object"); + ecode = -1; + goto e3; + } it_conf = ucl_object_iterate_new(conf_root); if (it_conf == NULL) { @@ -112,6 +117,8 @@ rtpp_cfile_process(const struct rtpp_cfg *csp) } while ((obj_file = ucl_object_iterate_safe(it_conf, true)) != NULL) { cf_key = ucl_object_key(obj_file); + if (cf_key == NULL) + continue; RTPP_LOG(csp->glog, RTPP_LOG_DBUG, "Entry: %s", cf_key); if (strcasecmp(cf_key, "modules") == 0) { #if ENABLE_MODULE_IF @@ -163,12 +170,22 @@ parse_modules(const struct rtpp_cfg *csp, const ucl_object_t *wop) const char *cp, *mp; struct rtpp_module_if *mif; + if (ucl_object_type(wop) != UCL_OBJECT) { + RTPP_LOG(csp->glog, RTPP_LOG_ERR, "Error: 'modules' section must be an object"); + return (-1); + } it_conf = ucl_object_iterate_new(wop); if (it_conf == NULL) return (-1); ecode = 0; while ((obj_file = ucl_object_iterate_safe(it_conf, true)) != NULL) { cf_key = ucl_object_key(obj_file); + if (cf_key == NULL || ucl_object_type(obj_file) != UCL_OBJECT) { + RTPP_LOG(csp->glog, RTPP_LOG_ERR, "Error: module '%s' configuration must be an object", + cf_key != NULL ? cf_key : "(null)"); + ecode = -1; + goto e0; + } RTPP_LOG(csp->glog, RTPP_LOG_DBUG, "\tmodule: %s", cf_key); obj_key = ucl_object_find_key(obj_file, "load"); if (obj_key == NULL) { @@ -259,6 +276,10 @@ conf_helper_mapper(struct rtpp_log *log, const ucl_object_t *obj, const conf_hel return (false); while ((cur = ucl_object_iterate_safe(it, true)) != NULL && ret) { key = ucl_object_key(cur); + if (key == NULL) { + ret = false; + break; + } found = false; for (i = 0; map[i].conf_key; i++) { if (strcasecmp(map[i].conf_key, key) != 0) From cfa8cec64e95a037eace8b64fd3af09ac0e88802 Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Sun, 15 Nov 2026 14:38:08 -0700 Subject: [PATCH 3/4] Update libucl subtree to sippy/libucl 4ec6115 Import parser error-path leak fixes already merged into the libucl fork. --- external/libucl/src/ucl_parser.c | 17 ++++++++++++++++- external/libucl/src/ucl_util.c | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/external/libucl/src/ucl_parser.c b/external/libucl/src/ucl_parser.c index 8e851ea9d..90e50f134 100644 --- a/external/libucl/src/ucl_parser.c +++ b/external/libucl/src/ucl_parser.c @@ -2705,7 +2705,19 @@ ucl_state_machine(struct ucl_parser *parser) macro_args = ucl_parse_macro_arguments(parser, chunk); p = chunk->pos; if (macro_args) { - SKIP_SPACES_COMMENTS(parser, chunk, p); + while (p < chunk->end) { + if (!ucl_test_character(*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) { + if (chunk->remain >= 2 && ucl_lex_is_comment(p[0], p[1])) { + if (!ucl_skip_comments(parser)) { + ucl_object_unref(macro_args); + return false; + } + p = chunk->pos; + } + break; + } + ucl_chunk_skipc(chunk, p); + } } } else { @@ -2713,6 +2725,9 @@ ucl_state_machine(struct ucl_parser *parser) } if (!ucl_parse_macro_value(parser, chunk, macro, ¯o_start, ¯o_len)) { + if (macro_args) { + ucl_object_unref(macro_args); + } parser->prev_state = parser->state; parser->state = UCL_STATE_ERROR; return false; diff --git a/external/libucl/src/ucl_util.c b/external/libucl/src/ucl_util.c index b25f715e0..5ac913e3a 100644 --- a/external/libucl/src/ucl_util.c +++ b/external/libucl/src/ucl_util.c @@ -643,7 +643,7 @@ void ucl_parser_free(struct ucl_parser *parser) } LL_FOREACH_SAFE(parser->trash_objs, tr, trtmp) { - ucl_object_free_internal(tr, false, ucl_object_dtor_free); + ucl_object_free_internal(tr, false, ucl_object_dtor_unref); } if (parser->err != NULL && parser->err != parser->_err_buf) { From 5333e151ef519025edbe5b9c0d17a27290e48d4d Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Sat, 14 Nov 2026 22:47:18 -0700 Subject: [PATCH 4/4] tests: cover non-object configuration parsing crashes Add config_types/confval1 to the serial test suite. It runs rtpproxy with configurations whose config root, "modules" section or module section is not an object (arrays and scalars). These used to reach strcasecmp() with a NULL key and crash; each must now be rejected with a nonzero exit status below 128, and not by a sanitizer deadly-signal report. --- tests/Makefile.am | 1 + tests/config_types/Makefile.ami | 3 +++ tests/config_types/confval1 | 21 +++++++++++++++++++ tests/config_types/nonobj_module_array.conf | 3 +++ tests/config_types/nonobj_module_elem.conf | 6 ++++++ tests/config_types/nonobj_module_scalar.conf | 3 +++ tests/config_types/nonobj_modules_array.conf | 1 + tests/config_types/nonobj_modules_scalar.conf | 1 + tests/config_types/nonobj_root_array.conf | 1 + 9 files changed, 40 insertions(+) create mode 100644 tests/config_types/Makefile.ami create mode 100755 tests/config_types/confval1 create mode 100644 tests/config_types/nonobj_module_array.conf create mode 100644 tests/config_types/nonobj_module_elem.conf create mode 100644 tests/config_types/nonobj_module_scalar.conf create mode 100644 tests/config_types/nonobj_modules_array.conf create mode 100644 tests/config_types/nonobj_modules_scalar.conf create mode 100644 tests/config_types/nonobj_root_array.conf diff --git a/tests/Makefile.am b/tests/Makefile.am index 50ab497df..47a0fbccc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,6 +8,7 @@ include $(srcdir)/recording/Makefile.ami include $(srcdir)/makeann/Makefile.ami include $(srcdir)/unittests/Makefile.ami include $(srcdir)/libucl/Makefile.ami +include $(srcdir)/config_types/Makefile.ami include $(srcdir)/libexecinfo/Makefile.ami include $(srcdir)/acct_rtcp_hep/Makefile.ami include $(srcdir)/acct_csv/Makefile.ami diff --git a/tests/config_types/Makefile.ami b/tests/config_types/Makefile.ami new file mode 100644 index 000000000..520ff7e25 --- /dev/null +++ b/tests/config_types/Makefile.ami @@ -0,0 +1,3 @@ +config_types_EXTRA_DIST = config_types +TESTS += config_types/confval1 +EXTRA_DIST += ${config_types_EXTRA_DIST} diff --git a/tests/config_types/confval1 b/tests/config_types/confval1 new file mode 100755 index 000000000..57aba3bd9 --- /dev/null +++ b/tests/config_types/confval1 @@ -0,0 +1,21 @@ +#!/bin/sh + +BASEDIR="`dirname "${0}"`/.." +. "${BASEDIR}/functions" + +# Configurations whose root, "modules" section or module section is not an +# object used to crash the parser (NULL key passed to strcasecmp()). They must +# be rejected with an error, not by crashing. +for cfile in nonobj_root_array nonobj_modules_array nonobj_modules_scalar \ + nonobj_module_array nonobj_module_scalar nonobj_module_elem +do + cf="config_types/${cfile}.conf" + log="config_types/${cfile}.log" + ${RTPPROXY} -f --config ${cf} -s stdio: < /dev/null > "${log}" 2>&1 + RC=${?} + # A crash shows up as a signal exit (>= 128), or as a sanitizer's deadly + # signal report with exit status 1 in sanitizer-instrumented builds. + [ ${RC} -ne 0 -a ${RC} -lt 128 ] && ! grep -q 'DEADLYSIGNAL\|Segmentation fault' "${log}" + report "non-object configuration rejected: ${cf} (rc=${RC})" + rm -f "${log}" +done diff --git a/tests/config_types/nonobj_module_array.conf b/tests/config_types/nonobj_module_array.conf new file mode 100644 index 000000000..0a768b49a --- /dev/null +++ b/tests/config_types/nonobj_module_array.conf @@ -0,0 +1,3 @@ +modules { + acct_csv [1, 2] +} diff --git a/tests/config_types/nonobj_module_elem.conf b/tests/config_types/nonobj_module_elem.conf new file mode 100644 index 000000000..0e5b5d67d --- /dev/null +++ b/tests/config_types/nonobj_module_elem.conf @@ -0,0 +1,6 @@ +modules { + acct_csv { + load = ./rtpp_acct_csv.so + [1] + } +} diff --git a/tests/config_types/nonobj_module_scalar.conf b/tests/config_types/nonobj_module_scalar.conf new file mode 100644 index 000000000..0de440215 --- /dev/null +++ b/tests/config_types/nonobj_module_scalar.conf @@ -0,0 +1,3 @@ +modules { + acct_csv = 5 +} diff --git a/tests/config_types/nonobj_modules_array.conf b/tests/config_types/nonobj_modules_array.conf new file mode 100644 index 000000000..f2fb02e8e --- /dev/null +++ b/tests/config_types/nonobj_modules_array.conf @@ -0,0 +1 @@ +modules [1, 2] diff --git a/tests/config_types/nonobj_modules_scalar.conf b/tests/config_types/nonobj_modules_scalar.conf new file mode 100644 index 000000000..17edb1d31 --- /dev/null +++ b/tests/config_types/nonobj_modules_scalar.conf @@ -0,0 +1 @@ +modules = 5 diff --git a/tests/config_types/nonobj_root_array.conf b/tests/config_types/nonobj_root_array.conf new file mode 100644 index 000000000..44e2ace7e --- /dev/null +++ b/tests/config_types/nonobj_root_array.conf @@ -0,0 +1 @@ +[1, 2]