Skip to content

Commit

Permalink
Make rtpp_cand_decode() use central log for errors when available.
Browse files Browse the repository at this point in the history
OSS-Fuzz issue 71353

Use spaces for identation consistently.
  • Loading branch information
sobomax committed Aug 22, 2024
1 parent 4906f72 commit 4b3581c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
2 changes: 1 addition & 1 deletion libre/libre_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ main(int argc, char **argv)
tiebrk, lufrag, lpwd, NULL, NULL) == 0);
for (int i=0; testv[i].c != 0; i++) {
const struct rtpp_command_argsp args = {.c=testv[i].c, .v=testv[i].v};
int err = rtpp_cand_decode(icem, &args);
int err = rtpp_cand_decode(icem, &args, NULL);
assert(err == 0);
}
assert(icem_comp_alloc(&comp, icem, id, sock) == 0);
Expand Down
4 changes: 3 additions & 1 deletion libre/rtpp_re.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

struct icem;
struct rtpp_command_argsp;
struct rtpp_log;

typedef void (mem_destroy_h)(void *data);

int rtpp_cand_decode(struct icem *icem, const struct rtpp_command_argsp *args);
int rtpp_cand_decode(struct icem *, const struct rtpp_command_argsp *,
struct rtpp_log *);
void *mem_deref(void *data);
void re_dbg_printf(int level, const char *buf, int len);

Expand Down
61 changes: 36 additions & 25 deletions libre/rtpp_re_icesdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ struct stun_msg;
#include "re_tmr.h"
#include "ice/ice.h"

#include "rtpp_types.h"
#include "rtpp_log.h"
#include "rtpp_log_obj.h"
#include "rtpp_command_args.h"

#define A2PL(a, i) S2PL(&(a)->v[i])
//#define A2PL(a, i) S2PL((a)->v + i)
#define S2PL(sp) (struct pl){.p=(sp)->s, .l=(sp)->len}
#define PL4P(pl) ((int)(pl).l), (pl).p

static enum ice_transp transp_resolve(const struct pl *transp)
{
Expand All @@ -31,20 +35,21 @@ static enum ice_transp transp_resolve(const struct pl *transp)
}

int
rtpp_cand_decode(struct icem *icem, const struct rtpp_command_argsp *args)
rtpp_cand_decode(struct icem *icem, const struct rtpp_command_argsp *args,
struct rtpp_log *log)
{
static const char rel_addr_str[] = "raddr";
static const char rel_port_str[] = "rport";
struct pl foundation, compid, transp, prio, addr, port, cand_type;
struct sa caddr, rel_addr;
char type[8];
uint8_t cid;
int err;
struct pl foundation, compid, transp, prio, addr, port, cand_type;
struct sa caddr, rel_addr;
char type[8];
uint8_t cid;
int err;

sa_init(&rel_addr, AF_INET);
sa_init(&rel_addr, AF_INET);

if (args->c < 8 || pl_strcasecmp(&A2PL(args, 6), "typ") != 0)
return EINVAL;
if (args->c < 8 || pl_strcasecmp(&A2PL(args, 6), "typ") != 0)
return EINVAL;

foundation = A2PL(args, 0);
compid = A2PL(args, 1);
Expand All @@ -55,12 +60,18 @@ rtpp_cand_decode(struct icem *icem, const struct rtpp_command_argsp *args)
cand_type = A2PL(args, 7);
struct rtpp_command_argsp extra = {.c = args->c - 8, .v = args->v + 8};

if (ICE_TRANSP_NONE == transp_resolve(&transp)) {
DEBUG_NOTICE("<%s> ignoring candidate with"
" unknown transport=%r (%r:%r)\n",
icem->name, &transp, &cand_type, &addr);
return EINVAL;
}
if (ICE_TRANSP_NONE == transp_resolve(&transp)) {
if (log == NULL) {
DEBUG_NOTICE("<%s> ignoring candidate with"
" unknown transport=%r (%r:%r)\n",
icem->name, &transp, &cand_type, &addr);
} else {
RTPP_LOG(log, RTPP_LOG_WARN, "<%s> ignoring candidate with"
" unknown transport=%.*s (%.*s:%.*s)",
icem->name, PL4P(transp), PL4P(cand_type), PL4P(addr));
}
return EINVAL;
}

/* Loop through " SP attr SP value" pairs */
while (extra.c >= 2) {
Expand All @@ -81,18 +92,18 @@ rtpp_cand_decode(struct icem *icem, const struct rtpp_command_argsp *args)
}
}

err = sa_set(&caddr, &addr, pl_u32(&port));
if (err)
return err;
err = sa_set(&caddr, &addr, pl_u32(&port));
if (err)
return err;

cid = pl_u32(&compid);
cid = pl_u32(&compid);

/* add only if not exist */
if (icem_cand_find(&icem->rcandl, cid, &caddr))
return 0;
/* add only if not exist */
if (icem_cand_find(&icem->rcandl, cid, &caddr))
return 0;

(void)pl_strcpy(&cand_type, type, sizeof(type));
(void)pl_strcpy(&cand_type, type, sizeof(type));

return icem_rcand_add(icem, ice_cand_name2type(type), cid,
pl_u32(&prio), &caddr, &rel_addr, &foundation);
return icem_rcand_add(icem, ice_cand_name2type(type), cid,
pl_u32(&prio), &caddr, &rel_addr, &foundation);
}
2 changes: 1 addition & 1 deletion modules/ice_lite/rtpp_ice_lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ ice_lite_candidate(struct ice_lite_agent_cfg *ila_c, int c, const rtpp_str_t *v)
{
struct rtpp_command_argsp args = {.c = c, .v = v};
pthread_mutex_lock(&ila_c->state_lock);
int err = rtpp_cand_decode(ila_c->icem, &args);
int err = rtpp_cand_decode(ila_c->icem, &args, RTPP_MOD_SELF.log);
pthread_mutex_unlock(&ila_c->state_lock);
return (err);
}
Expand Down

0 comments on commit 4b3581c

Please sign in to comment.