Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion external/libucl/src/ucl_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2705,14 +2705,29 @@ 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 {
macro_args = NULL;
}
if (!ucl_parse_macro_value(parser, chunk, macro,
&macro_start, &macro_len)) {
if (macro_args) {
ucl_object_unref(macro_args);
}
parser->prev_state = parser->state;
parser->state = UCL_STATE_ERROR;
return false;
Expand Down
2 changes: 1 addition & 1 deletion external/libucl/src/ucl_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
modules {
ice_lite {
}
catch_dtmf {
load = 42
}
}
12 changes: 12 additions & 0 deletions scripts/fuzz/config_fuzzer_seeds/seed_modules_dso.conf
Original file line number Diff line number Diff line change
@@ -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
}
}
11 changes: 11 additions & 0 deletions scripts/fuzz/config_fuzzer_seeds/seed_unknown_keys.conf
Original file line number Diff line number Diff line change
@@ -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 }
}
}
93 changes: 93 additions & 0 deletions scripts/fuzz/fuzz_config_file.c
Original file line number Diff line number Diff line change
@@ -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 <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#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);
}
54 changes: 54 additions & 0 deletions scripts/fuzz/fuzz_config_file.dict
Original file line number Diff line number Diff line change
@@ -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@"
25 changes: 24 additions & 1 deletion scripts/fuzz/oss-fuzz-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/rtpp_cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/config_types/Makefile.ami
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config_types_EXTRA_DIST = config_types
TESTS += config_types/confval1
EXTRA_DIST += ${config_types_EXTRA_DIST}
21 changes: 21 additions & 0 deletions tests/config_types/confval1
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tests/config_types/nonobj_module_array.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
modules {
acct_csv [1, 2]
}
6 changes: 6 additions & 0 deletions tests/config_types/nonobj_module_elem.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
modules {
acct_csv {
load = ./rtpp_acct_csv.so
[1]
}
}
3 changes: 3 additions & 0 deletions tests/config_types/nonobj_module_scalar.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
modules {
acct_csv = 5
}
1 change: 1 addition & 0 deletions tests/config_types/nonobj_modules_array.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
modules [1, 2]
1 change: 1 addition & 0 deletions tests/config_types/nonobj_modules_scalar.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
modules = 5
1 change: 1 addition & 0 deletions tests/config_types/nonobj_root_array.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1, 2]