Skip to content

Commit

Permalink
srtp: fix possible datarace on st->got_sdp bool. make it atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
cHuberCoffee committed Apr 26, 2024
1 parent 4db5ab4 commit 9b54c5b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/srtp/srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct menc_st {
struct srtp *srtp_tx, *srtp_rx;
mtx_t *mtx_tx, *mtx_rx;
RE_ATOMIC bool use_srtp;
bool got_sdp;
RE_ATOMIC bool got_sdp;
char *crypto_suite;

void *rtpsock;
Expand Down Expand Up @@ -255,7 +255,7 @@ static bool recv_handler(struct sa *src, struct mbuf *mb, void *arg)
int err = 0;
(void)src;

if (!st->got_sdp)
if (!re_atomic_rlx(&st->got_sdp))
return true; /* drop the packet */

if (!re_atomic_rlx(&st->use_srtp) || !is_rtp_or_rtcp(mb))
Expand Down Expand Up @@ -547,7 +547,7 @@ static int media_alloc(struct menc_media **stp, struct menc_sess *sess,
/* SDP handling */

if (sdp_media_rport(sdpm))
st->got_sdp = true;
re_atomic_rlx_set(&st->got_sdp, true);

if (sdp_media_rattr(st->sdpm, "crypto")) {

Expand Down

0 comments on commit 9b54c5b

Please sign in to comment.