Skip to content

Commit

Permalink
Merge branch 'main' into coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Dec 20, 2023
2 parents b7ade60 + 1d23051 commit 34e66c7
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 50 deletions.
6 changes: 5 additions & 1 deletion rem/aumix/aumix.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ static void destructor(void *arg)
{
struct aumix *mix = arg;

if (mix->run) {
mtx_lock(&mix->mutex);
bool run = mix->run;
mtx_unlock(&mix->mutex);

if (run) {

mtx_lock(&mix->mutex);
mix->run = false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ static int poll_setup(struct re *re)
/**
* Listen for events on a file descriptor
*
* @param fhs File descriptor handler struct pointer (don't use mem_deref(),
* @param fhsp File descriptor handler struct pointer (don't use mem_deref(),
* use fd_close() instead)
* @param fd File descriptor
* @param flags Wanted event flags
Expand Down
44 changes: 41 additions & 3 deletions src/sip/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct sip_dialog {
uint32_t lseq;
uint32_t rseq;
size_t cpos;
size_t rpos;
enum sip_transp tp;
uint32_t srcport;
};
Expand Down Expand Up @@ -118,6 +119,7 @@ int sip_dialog_alloc(struct sip_dialog **dlgp,
if (i == 0)
rend = dlg->mb->pos - 2;
}
dlg->rpos = dlg->mb->pos;
err |= mbuf_printf(dlg->mb, "To: <%s>\r\n", to_uri);
dlg->cpos = dlg->mb->pos;
err |= mbuf_printf(dlg->mb, "From: %s%s%s<%s>;tag=%016llx\r\n",
Expand Down Expand Up @@ -231,7 +233,9 @@ int sip_dialog_accept(struct sip_dialog **dlgp, const struct sip_msg *msg)

err |= sip_msg_hdr_apply(msg, true, SIP_HDR_RECORD_ROUTE,
record_route_handler, &renc) ? ENOMEM : 0;
dlg->rpos = dlg->mb->pos;
err |= mbuf_printf(dlg->mb, "To: %r\r\n", &msg->from.val);
dlg->cpos = dlg->mb->pos;
err |= mbuf_printf(dlg->mb, "From: %r;tag=%016llx\r\n", &msg->to.val,
msg->tag);
if (err)
Expand Down Expand Up @@ -304,10 +308,12 @@ int sip_dialog_create(struct sip_dialog *dlg, const struct sip_msg *msg)

err |= sip_msg_hdr_apply(msg, msg->req, SIP_HDR_RECORD_ROUTE,
record_route_handler, &renc) ? ENOMEM : 0;
dlg->rpos = renc.mb->pos;
err |= mbuf_printf(renc.mb, "To: %r\r\n",
msg->req ? &msg->from.val : &msg->to.val);

dlg->mb->pos = dlg->cpos;
dlg->cpos = renc.mb->pos;
err |= mbuf_write_mem(renc.mb, mbuf_buf(dlg->mb),
mbuf_get_left(dlg->mb));
dlg->mb->pos = 0;
Expand Down Expand Up @@ -344,7 +350,6 @@ int sip_dialog_create(struct sip_dialog *dlg, const struct sip_msg *msg)
dlg->rtag = mem_ref(rtag);
dlg->uri = mem_ref(uri);
dlg->rseq = msg->req ? msg->cseq.num : 0;
dlg->cpos = 0;
dlg->tp = msg->tp;

out:
Expand Down Expand Up @@ -462,6 +467,9 @@ int sip_dialog_update(struct sip_dialog *dlg, const struct sip_msg *msg)
{
const struct sip_hdr *contact;
struct sip_addr addr;
struct mbuf *mb;
struct pl pl;
size_t cpos;
char *uri;
int err;

Expand All @@ -479,10 +487,34 @@ int sip_dialog_update(struct sip_dialog *dlg, const struct sip_msg *msg)
if (err)
return err;

mb = mbuf_alloc(512);
if (!mb)
return ENOMEM;

err = mbuf_write_mem(mb, mbuf_buf(dlg->mb), dlg->rpos);
err |= mbuf_printf(mb, "To: %r\r\n",
msg->req ? &msg->from.val : &msg->to.val);
cpos = mb->pos;
err |= mbuf_write_mem(mb, mbuf_buf(dlg->mb) + dlg->cpos,
mbuf_get_left(dlg->mb) - dlg->cpos);

if (err)
goto out;

dlg->cpos = cpos;
mb->pos = 0;

mem_deref(dlg->rtag);
err = pl_strdup(&dlg->rtag, msg->req ? &msg->from.tag : &msg->to.tag);
if (err)
return err;

mem_deref(dlg->mb);
dlg->mb = mem_ref(mb);

if (dlg->route.scheme.p == dlg->uri) {

struct uri tmp;
struct pl pl;

pl_set_str(&pl, uri);
err = uri_decode(&tmp, &pl);
Expand All @@ -491,11 +523,17 @@ int sip_dialog_update(struct sip_dialog *dlg, const struct sip_msg *msg)

dlg->route = tmp;
}
else {
pl.p = (const char *)mbuf_buf(dlg->mb) + ROUTE_OFFSET;
pl.l = dlg->rpos - ROUTE_OFFSET;
err = sip_addr_decode(&addr, &pl);
dlg->route = addr.uri;
}

mem_deref(dlg->uri);
dlg->uri = mem_ref(uri);

out:
mem_deref(mb);
mem_deref(uri);

return err;
Expand Down
3 changes: 2 additions & 1 deletion src/sipsess/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg)
goto out;
}

if (pl_isset(&msg->to.tag)) {
contact = sip_msg_hdr(msg, SIP_HDR_CONTACT);
if (pl_isset(&msg->to.tag) && contact) {
err = sip_dialog_established(sess->dlg) ?
sip_dialog_update(sess->dlg, msg) :
sip_dialog_create(sess->dlg, msg);
Expand Down
Loading

0 comments on commit 34e66c7

Please sign in to comment.