Skip to content

Commit

Permalink
Set RTPP_DEBUG_refcnt, enable tracing for the cmd->reply->rcnt
Browse files Browse the repository at this point in the history
and check that both cmd->reply and cmd->reply->rcnt are intact
after running a test case. This is to debug fuzzer-triggered
memory leaks.
  • Loading branch information
sobomax committed Sep 10, 2024
1 parent f417ae8 commit bd66b11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/fuzz/oss-fuzz-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ LD="lld"
LD_BIN="ld.lld"
LDFLAGS="-fuse-ld=${LD}"

CFLAGS="${CFLAGS} -DRTPP_DEBUG_refcnt=1"
CXXFLAGS="${CXXFLAGS} -DRTPP_DEBUG_refcnt=1"

if ! AR=llvm-ar RANLIB=llvm-ranlib NM=llvm-nm STRIP=llvm-strip \
LDFLAGS="${LDFLAGS}" ./configure --enable-librtpproxy --enable-lto \
--enable-silent --enable-noinst=no
LDFLAGS="${LDFLAGS}" CFLAGS="${CFLAGS}" ./configure --enable-librtpproxy \
--enable-lto --enable-silent --enable-noinst=no
then
cat config.log
exit 1
Expand Down
8 changes: 8 additions & 0 deletions scripts/fuzz/rfz_command.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <sys/socket.h>
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -8,11 +9,13 @@

#include "rtpp_types.h"
#include "rtpp_cfg.h"
#include "rtpp_codeptr.h"
#include "rtpp_refcnt.h"
#include "rtpp_command.h"
#include "rtpp_command_args.h"
#include "rtpp_command_sub.h"
#include "rtpp_command_private.h"
#include "rtpp_command_reply.h"
#include "rtpp_command_stats.h"
#include "rtpp_time.h"

Expand All @@ -33,13 +36,18 @@ ExecuteRTPPCommand(struct rtpp_conf *gcp, const char *data, size_t size)
cmd = rtpp_command_ctor(gcp->cfsp, gcp->tfd, &dtime, &cstat, 0);
if (cmd == NULL)
return (-1);
const void *tp = cmd->reply;
const void *trp = cmd->reply->rcnt;
CALL_SMETHOD(cmd->reply->rcnt, traceen, HEREVAL);
memcpy(cmd->buf, data, size);
cmd->buf[size] = '\0';

rval = rtpp_command_split(cmd, size, &rval, NULL);
if (rval == 0) {
rval = handle_command(gcp->cfsp, cmd);
}
assert(tp == cmd->reply);
assert(trp == cmd->reply->rcnt);
free_command(cmd);
return (rval);
}

0 comments on commit bd66b11

Please sign in to comment.