From 84eca4dc08ea57c4452f8ce0c9390883ae5ac15b Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 12 Dec 2022 14:52:34 -0500 Subject: [PATCH] MT#55283 fix time tracking race condition 1) Read dtxb->start while the lock is held (not strictly necessary as the read should be atomic anyway) 2) Expect that dtxb->start can be larger than rtpe_now.tv The latter can happen as `rtpe_now` in a timer thread is faked to be exactly the time when the timer was supposed to run, and not the actual current time, which means that a newly added packet can have a later time stamp than the "now" the timer thread is using. Change-Id: I48fd7f78af97c6d5b802e5151d69855a90f4032d --- daemon/codec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/daemon/codec.c b/daemon/codec.c index 331a5fbaf..eee4b7635 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -2652,6 +2652,7 @@ static void __dtx_send_later(struct timerthread_queue *ttq, void *p) { } int ptime = dtxb->ptime; + time_t dtxb_start = dtxb->start; mutex_unlock(&dtxb->lock); @@ -2673,7 +2674,7 @@ static void __dtx_send_later(struct timerthread_queue *ttq, void *p) { "Decoder error while processing buffered RTP packet"); } else { - unsigned int diff = rtpe_now.tv_sec - dtxb->start; + int diff = rtpe_now.tv_sec - dtxb_start; if (rtpe_config.max_dtx <= 0 || diff < rtpe_config.max_dtx) { ilogs(dtx, LOG_DEBUG, "RTP media for TS %lu missing, triggering DTX", ts);