From 28e3ca3dcef9a3a3864909149b04ee4f5222d3e7 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 13 Jan 2022 15:47:37 -0500 Subject: [PATCH] TT#14008 fix possible NULL pointer dereference Change-Id: I601676f2cb1722d936e055ab7270b6668150b4ba Warned-by: coverity --- daemon/codec.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/daemon/codec.c b/daemon/codec.c index 215bd29a4..e5b17681a 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -1628,19 +1628,23 @@ static int __handler_func_sequencer(struct media_packet *mp, struct transcode_pa break; } - uint32_t ts_diff = ch->last_ts - packet->ts; - if (ts_diff < 0x80000000) { // ch->last_ts >= packet->ts - // multiple consecutive packets with same TS: this could be a compound packet, e.g. a large video frame, or - // it could be a supplemental audio codec with static timestamps, in which case we adjust the TS forward - // by one frame length. This is needed so that the next real audio packet (with real TS) is not mistakenly - // seen as overdue - if (h->source_pt.codec_def && h->source_pt.codec_def->supplemental) - ch->last_ts += h->source_pt.clock_rate * (ch->ptime ?: 20) / 1000; + if (ch) { + uint32_t ts_diff = ch->last_ts - packet->ts; + if (ts_diff < 0x80000000) { // ch->last_ts >= packet->ts + // multiple consecutive packets with same TS: this could be a compound packet, e.g. a large video frame, or + // it could be a supplemental audio codec with static timestamps, in which case we adjust the TS forward + // by one frame length. This is needed so that the next real audio packet (with real TS) is not mistakenly + // seen as overdue + if (h->source_pt.codec_def && h->source_pt.codec_def->supplemental) + ch->last_ts += h->source_pt.clock_rate * (ch->ptime ?: 20) / 1000; + } + else + ch->last_ts = packet->ts; + + if (input_ch) + input_ch->last_ts = ch->last_ts; } - else - ch->last_ts = packet->ts; - input_ch->last_ts = ch->last_ts; // new packet might have different handlers h = packet->handler;