Ticket #7149: libs_libmythtv-pointer-checks-ticket-7149

File libs_libmythtv-pointer-checks-ticket-7149, 12.8 KB (added by Erik Hovland <erik@…>, 10 years ago)

Same patch as before but against trunk as of 2010-02-03

Line 
1Pointer validity checking defectsg
2
3From: Erik Hovland <erik@hovland.org>
4
51. player_ctx is dereferenced many times before it is checked in this
6   conditional. If player_ctx is going to be checked in this function
7   it likely should be the first thing doneg
8
92. New set of ringBuffer checking. Plus an ic check
10
113. mon needs to be checked before dereferencingg
12
134. rotor checking
14
155. FiltChain needs checking
16
176. return if _rtsp_client is invalid, that way it isn't
18   dereferenced a few lines laterg
19
207. Check m_priv
21
228. Check mctx before hitting its locksg
23
249. Calling SetErrored on ctx will dereference ctxg
25
2610. Assign pointer from GetSet() so that we don't call GetSet twice
27
2811. Check mctx againg
29
3012. Don't need to check mctx now since we did it earlier
31
3213. Check actx
33
3414. Check validity of osd
35
3615. Another mctx check
37
3816. And another time where we can remove a check because we now do it
39    earlier
40
4117. osd checks
42
4318. Check frame
44
4519. Check m_ctx
46
4720. vsz_tmp_buf will be dereferenced by ShutdownVideoResize so move the
48    check up
49
5021. Remove later check
51---
52
53 mythtv/libs/libmythtv/NuppelVideoPlayer.cpp        |    2 -
54 mythtv/libs/libmythtv/avformatdecoder.cpp          |    9 ++-
55 .../libs/libmythtv/channelscan/channelscanner.cpp  |    2 -
56 mythtv/libs/libmythtv/dvbsignalmonitor.cpp         |    2 +
57 mythtv/libs/libmythtv/filtermanager.cpp            |    2 -
58 mythtv/libs/libmythtv/iptv/iptvfeederrtsp.cpp      |    1
59 mythtv/libs/libmythtv/linuxfirewiredevice.cpp      |    3 +
60 mythtv/libs/libmythtv/nuppeldecoder.cpp            |    2 +
61 mythtv/libs/libmythtv/tv_play.cpp                  |   54 +++++++++++++-------
62 mythtv/libs/libmythtv/videooutbase.cpp             |    4 +
63 10 files changed, 55 insertions(+), 26 deletions(-)
64
65
66diff --git a/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp b/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp
67index 1c4c8cb..daac20a 100644
68--- a/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp
69+++ b/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp
70@@ -4640,7 +4640,7 @@ bool NuppelVideoPlayer::IsNearEnd(long long margin) const
71 
72     framesRead = GetDecoder()->GetFramesRead();
73 
74-    if (player_ctx && !player_ctx->IsPIP() &&
75+    if (!player_ctx->IsPIP() &&
76         player_ctx->GetState() == kState_WatchingPreRecorded)
77     {
78         framesLeft = margin;
79diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
80index 6e25859..03b5dd2 100644
81--- a/mythtv/libs/libmythtv/avformatdecoder.cpp
82+++ b/mythtv/libs/libmythtv/avformatdecoder.cpp
83@@ -1330,7 +1330,7 @@ void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc,
84 
85     float aspect_ratio = 0.0;
86 
87-    if (ringBuffer->isDVD())
88+    if (ringBuffer && ringBuffer->isDVD())
89         directrendering = false;
90 
91     if (selectedStream)
92@@ -1758,7 +1758,7 @@ int AvFormatDecoder::ScanStreams(bool novideo)
93     map<int,uint> lang_sub_cnt;
94     map<int,uint> lang_aud_cnt;
95 
96-    if (ringBuffer->isDVD() &&
97+    if (ringBuffer && ringBuffer->isDVD() &&
98         ringBuffer->DVD()->AudioStreamsChanged())
99     {
100         ringBuffer->DVD()->AudioStreamsChanged(false);
101@@ -2329,6 +2329,9 @@ int get_avf_buffer(struct AVCodecContext *c, AVFrame *pic)
102 
103     VideoFrame *frame = nd->GetNVP()->GetNextVideoFrame(true);
104 
105+    if (!frame)
106+        return 0;
107+
108     for (int i = 0; i < 3; i++)
109     {
110         pic->data[i]     = frame->buf + frame->offsets[i];
111@@ -4556,7 +4559,7 @@ bool AvFormatDecoder::SetupAudioStream(void)
112     AudioInfo old_in  = audioIn;
113     bool using_passthru = false;
114 
115-    if ((currentTrack[kTrackTypeAudio] >= 0) &&
116+    if ((currentTrack[kTrackTypeAudio] >= 0) && ic &&
117         (selectedTrack[kTrackTypeAudio].av_stream_index <=
118          (int) ic->nb_streams) &&
119         (curstream = ic->streams[selectedTrack[kTrackTypeAudio]
120diff --git a/mythtv/libs/libmythtv/channelscan/channelscanner.cpp b/mythtv/libs/libmythtv/channelscan/channelscanner.cpp
121index e026206..7560f18 100644
122--- a/mythtv/libs/libmythtv/channelscan/channelscanner.cpp
123+++ b/mythtv/libs/libmythtv/channelscan/channelscanner.cpp
124@@ -419,7 +419,7 @@ void ChannelScanner::PreScanCommon(
125 
126 #ifdef USING_DVB
127     dvbm = sigmonScanner->GetDVBSignalMonitor();
128-    if (dvbm)
129+    if (dvbm && mon)
130         using_rotor = mon->HasFlags(SignalMonitor::kDVBSigMon_WaitForPos);
131 #endif // USING_DVB
132 
133diff --git a/mythtv/libs/libmythtv/dvbsignalmonitor.cpp b/mythtv/libs/libmythtv/dvbsignalmonitor.cpp
134index c2742b7..d699c92 100644
135--- a/mythtv/libs/libmythtv/dvbsignalmonitor.cpp
136+++ b/mythtv/libs/libmythtv/dvbsignalmonitor.cpp
137@@ -129,6 +129,8 @@ void DVBSignalMonitor::GetRotorStatus(bool &was_moving, bool &is_moving)
138         return;
139 
140     const DiSEqCDevRotor *rotor = dvbchannel->GetRotor();
141+    if (!rotor)
142+        return;
143 
144     QMutexLocker locker(&statusLock);
145     was_moving = rotorPosition.GetValue() < 100;
146diff --git a/mythtv/libs/libmythtv/filtermanager.cpp b/mythtv/libs/libmythtv/filtermanager.cpp
147index c5e360b..fd5056b 100644
148--- a/mythtv/libs/libmythtv/filtermanager.cpp
149+++ b/mythtv/libs/libmythtv/filtermanager.cpp
150@@ -402,7 +402,7 @@ FilterChain *FilterManager::LoadFilters(QString Filters,
151             break;
152         }
153 
154-        if (NewFilt->filter)
155+        if (NewFilt->filter && FiltChain)
156         {
157             FiltChain->Append(NewFilt);
158         }
159diff --git a/mythtv/libs/libmythtv/iptv/iptvfeederrtsp.cpp b/mythtv/libs/libmythtv/iptv/iptvfeederrtsp.cpp
160index 47b4921..f887574 100644
161--- a/mythtv/libs/libmythtv/iptv/iptvfeederrtsp.cpp
162+++ b/mythtv/libs/libmythtv/iptv/iptvfeederrtsp.cpp
163@@ -107,6 +107,7 @@ bool IPTVFeederRTSP::Open(const QString &url)
164                 QString("Failed to create RTSP client: %1")
165                 .arg(_live_env->getResultMsg()));
166         FreeEnv();
167+        return false;
168     }
169 
170     // Setup URL for the current session
171diff --git a/mythtv/libs/libmythtv/linuxfirewiredevice.cpp b/mythtv/libs/libmythtv/linuxfirewiredevice.cpp
172index 4607e77..35ed055 100644
173--- a/mythtv/libs/libmythtv/linuxfirewiredevice.cpp
174+++ b/mythtv/libs/libmythtv/linuxfirewiredevice.cpp
175@@ -984,6 +984,9 @@ LinuxAVCInfo *LinuxFirewireDevice::GetInfoPtr(void)
176 
177 const LinuxAVCInfo *LinuxFirewireDevice::GetInfoPtr(void) const
178 {
179+    if (!m_priv)
180+        return NULL;
181+
182     avcinfo_list_t::iterator it = m_priv->devices.find(m_guid);
183     return (it == m_priv->devices.end()) ? NULL : *it;
184 }
185diff --git a/mythtv/libs/libmythtv/nuppeldecoder.cpp b/mythtv/libs/libmythtv/nuppeldecoder.cpp
186index 4a83849..5623bf0 100644
187--- a/mythtv/libs/libmythtv/nuppeldecoder.cpp
188+++ b/mythtv/libs/libmythtv/nuppeldecoder.cpp
189@@ -1152,6 +1152,8 @@ bool NuppelDecoder::GetFrame(DecodeType decodetype)
190             }
191 
192             VideoFrame *buf = GetNVP()->GetNextVideoFrame();
193+            if (!buf)
194+                continue;
195 
196             ret = DecodeFrame(&frameheader, strm, buf);
197             if (!ret)
198diff --git a/mythtv/libs/libmythtv/tv_play.cpp b/mythtv/libs/libmythtv/tv_play.cpp
199index e1e5bdd..7762b83 100644
200--- a/mythtv/libs/libmythtv/tv_play.cpp
201+++ b/mythtv/libs/libmythtv/tv_play.cpp
202@@ -363,10 +363,14 @@ bool TV::StartTV(ProgramInfo *tvrec, bool startInGuide,
203         const PlayerContext *mctx =
204             tv->GetPlayerReadLock(0, __FILE__, __LINE__);
205         quitAll = tv->wantsToQuit || (mctx && mctx->errored);
206-        mctx->LockDeleteNVP(__FILE__, __LINE__);
207-        if (mctx->nvp && mctx->nvp->IsErrored())
208-            nvpError = mctx->nvp->GetError();
209-        mctx->UnlockDeleteNVP(__FILE__, __LINE__);
210+        if (mctx)
211+        {
212+            mctx->LockDeleteNVP(__FILE__, __LINE__);
213+            if (mctx->nvp && mctx->nvp->IsErrored())
214+                nvpError = mctx->nvp->GetError();
215+
216+            mctx->UnlockDeleteNVP(__FILE__, __LINE__);
217+        }
218         tv->ReturnPlayerLock(mctx);
219     }
220 
221@@ -2529,7 +2533,6 @@ void TV::timerEvent(QTimerEvent *te)
222         if (!ok || !pbinfo)
223         {
224             VERBOSE(VB_IMPORTANT, LOC_ERR + "lost contact with backend");
225-            SetErrored(ctx);
226         }
227 
228         ReturnPlayerLock(mctx);
229@@ -2884,8 +2887,9 @@ void TV::timerEvent(QTimerEvent *te)
230     {
231         PlayerContext *actx = GetPlayerReadLock(-1, __FILE__, __LINE__);
232         OSD *osd = GetOSDLock(actx);
233-        if (osd && osd->GetSet("status") &&
234-            osd->GetSet("status")->Displaying() &&
235+        OSDSet *osdset = NULL;
236+        if (osd && (osdset = osd->GetSet("status")) &&
237+            osdset->Displaying() &&
238             (StateIsLiveTV(actx->GetState()) ||
239              StateIsPlaying(actx->GetState())))
240         {
241@@ -2914,6 +2918,8 @@ void TV::timerEvent(QTimerEvent *te)
242     {
243         bool error = false;
244         PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
245+        if (!mctx)
246+            return;
247 
248         if (mctx->IsNVPErrored())
249         {
250@@ -2941,7 +2947,7 @@ void TV::timerEvent(QTimerEvent *te)
251             error = true;
252         }
253 
254-        for (uint i = 0; mctx && (i < player.size()); i++)
255+        for (uint i = 0; i < player.size(); i++)
256         {
257             PlayerContext *ctx = GetPlayer(mctx, i);
258             if (error || ctx->IsErrored())
259@@ -3347,7 +3353,7 @@ void TV::HandleSpeedChangeTimerEvent(void)
260         update_msg |= ctx->HandleNVPSpeedChangeEOF() && (ctx == actx);
261     }
262 
263-    if (update_msg)
264+    if (actx && update_msg)
265     {
266         UpdateOSDSeekMessage(actx, actx->GetPlayMessage(),
267                              osd_general_timeout);
268@@ -7506,16 +7512,19 @@ void TV::UpdateOSDSignal(const PlayerContext *ctx, const QStringList &strlist)
269     else if (!msg.isEmpty())
270         sigDesc = msg;
271 
272+    infoMap["description"] = sigDesc;
273     //osd->ClearAllText("signal_info");
274     //osd->SetText("signal_info", infoMap, -1);
275 
276     osd = GetOSDLock(ctx);
277-    osd->ClearAllText("channel_number");
278-    osd->SetText("channel_number", infoMap, osd_prog_info_timeout);
279+    if (osd)
280+    {
281+        osd->ClearAllText("channel_number");
282+        osd->SetText("channel_number", infoMap, osd_prog_info_timeout);
283 
284-    infoMap["description"] = sigDesc;
285-    osd->ClearAllText("program_info");
286-    osd->SetText("program_info", infoMap, osd_prog_info_timeout);
287+        osd->ClearAllText("program_info");
288+        osd->SetText("program_info", infoMap, osd_prog_info_timeout);
289+    }
290     ReturnOSDLock(ctx, osd);
291 
292     ctx->lastSignalMsg.clear();
293@@ -8638,13 +8647,16 @@ void TV::customEvent(QEvent *e)
294                 << " haslater: " << haslater);
295 
296         PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
297+        if (!mctx)
298+            return;
299+
300         if (mctx->recorder && cardnum == mctx->GetCardID())
301         {
302             AskAllowRecording(mctx, me->ExtraDataList(),
303                               timeuntil, hasrec, haslater);
304         }
305 
306-        for (uint i = 1; mctx && (i < player.size()); i++)
307+        for (uint i = 1; i < player.size(); i++)
308         {
309             PlayerContext *ctx = GetPlayer(mctx, i);
310             if (ctx->recorder && ctx->GetCardID() == cardnum)
311@@ -10879,7 +10891,9 @@ void TV::ToggleAutoExpire(PlayerContext *ctx)
312         if (ctx->CalcNVPSliderPosition(posInfo))
313         {
314             OSD *osd = GetOSDLock(ctx);
315-            osd->ShowStatus(posInfo, false, desc, 1);
316+            if (osd)
317+                osd->ShowStatus(posInfo, false, desc, 1);
318+
319             ReturnOSDLock(ctx, osd);
320         }
321         SetUpdateOSDPosition(false);
322@@ -10905,7 +10919,9 @@ void TV::SetAutoCommercialSkip(const PlayerContext *ctx,
323         if (ctx->CalcNVPSliderPosition(posInfo))
324         {
325             OSD *osd = GetOSDLock(ctx);
326-            osd->ShowStatus(posInfo, false, desc, 1);
327+            if (osd)
328+                osd->ShowStatus(posInfo, false, desc, 1);
329+
330             ReturnOSDLock(ctx, osd);
331         }
332         SetUpdateOSDPosition(false);
333@@ -10927,7 +10943,9 @@ void TV::SetManualZoom(const PlayerContext *ctx, bool zoomON, QString desc)
334         if (ctx->CalcNVPSliderPosition(posInfo))
335         {
336             OSD *osd = GetOSDLock(ctx);
337-            osd->ShowStatus(posInfo, false, desc, 1);
338+            if (osd)
339+                osd->ShowStatus(posInfo, false, desc, 1);
340+
341             ReturnOSDLock(ctx, osd);
342         }
343         SetUpdateOSDPosition(false);
344diff --git a/mythtv/libs/libmythtv/videooutbase.cpp b/mythtv/libs/libmythtv/videooutbase.cpp
345index a674159..f7b081a 100644
346--- a/mythtv/libs/libmythtv/videooutbase.cpp
347+++ b/mythtv/libs/libmythtv/videooutbase.cpp
348@@ -1150,7 +1150,7 @@ void VideoOutput::ResizeVideo(VideoFrame *frame)
349     // if resize == existing frame, no need to carry on
350     abort |= !resize.left() && !resize.top() && (resize.size() == frameDim);
351 
352-    if (abort)
353+    if (abort || !vsz_tmp_buf)
354     {
355         vsz_enabled = false;
356         ShutdownVideoResize();
357@@ -1160,7 +1160,7 @@ void VideoOutput::ResizeVideo(VideoFrame *frame)
358 
359     DoVideoResize(frameDim, resize.size());
360 
361-    if (vsz_tmp_buf && vsz_scale_context)
362+    if (vsz_scale_context)
363     {
364         AVPicture img_in, img_out;
365