From 278b4e8baab66c61bd46a429159b2851fc6de08c Mon Sep 17 00:00:00 2001
From: Lawrence Rust <lvr@softsystem.co.uk>
Date: Fri, 5 Aug 2011 11:31:08 +0200
Subject: [PATCH] freemheg: Fix error handling during Launch
If a Launch fails then either:
- a NULL dereference can occur
- or the MHEG engine can be left without an executing program.
Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
---
mythtv/libs/libmythfreemheg/Engine.cpp | 67 ++++++++++++++++++++++---------
1 files changed, 47 insertions(+), 20 deletions(-)
diff --git a/mythtv/libs/libmythfreemheg/Engine.cpp b/mythtv/libs/libmythfreemheg/Engine.cpp
index 3ef0825..2f12c82 100644
a
|
b
|
bool MHEngine::Launch(const MHObjectRef &target, bool fIsSpawn) |
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | |
| 275 | MHApplication *pProgram = (MHApplication*)ParseProgram(text); |
| 276 | if (! pProgram) |
| 277 | { |
| 278 | MHLOG(MHLogWarning, "Empty application"); |
| 279 | return false; |
| 280 | } |
| 281 | if (! pProgram->m_fIsApp) |
| 282 | { |
| 283 | MHLOG(MHLogWarning, "Expected an application"); |
| 284 | delete pProgram; |
| 285 | return false; |
| 286 | } |
| 287 | if ((__mhlogoptions & MHLogScenes) && __mhlogStream != 0) // Print it so we know what's going on. |
| 288 | { |
| 289 | pProgram->PrintMe(__mhlogStream, 0); |
| 290 | } |
| 291 | |
275 | 292 | // Clear the action queue of anything pending. |
276 | 293 | m_ActionStack.clear(); |
277 | 294 | |
… |
… |
bool MHEngine::Launch(const MHObjectRef &target, bool fIsSpawn) |
300 | 317 | } |
301 | 318 | } |
302 | 319 | |
303 | | MHApplication *pProgram = (MHApplication *)ParseProgram(text); |
304 | | |
305 | | if ((__mhlogoptions & MHLogScenes) && __mhlogStream != 0) // Print it so we know what's going on. |
306 | | { |
307 | | pProgram->PrintMe(__mhlogStream, 0); |
308 | | } |
309 | | |
310 | | if (! pProgram->m_fIsApp) |
311 | | { |
312 | | MHERROR("Expected an application"); |
313 | | } |
314 | | |
315 | 320 | // Save the path we use for this app. |
316 | 321 | pProgram->m_Path = csPath; // Record the path |
317 | 322 | int nPos = pProgram->m_Path.lastIndexOf('/'); |
… |
… |
void MHEngine::TransitionToScene(const MHObjectRef &target) |
417 | 422 | // Parse and run the file. |
418 | 423 | MHGroup *pProgram = ParseProgram(text); |
419 | 424 | |
| 425 | if (!pProgram ) |
| 426 | MHERROR("Empty scene"); |
| 427 | |
420 | 428 | if (pProgram->m_fIsApp) |
421 | 429 | { |
| 430 | delete pProgram; |
422 | 431 | MHERROR("Expected a scene"); |
423 | 432 | } |
424 | 433 | |
… |
… |
void MHEngine::RequestExternalContent(MHIngredient *pRequester) |
964 | 973 | return; |
965 | 974 | } |
966 | 975 | |
967 | | QByteArray text; |
968 | | |
969 | | if (m_Context->CheckCarouselObject(csPath) && m_Context->GetCarouselData(csPath, text)) |
| 976 | if (m_Context->CheckCarouselObject(csPath)) |
970 | 977 | { |
971 | 978 | // Available now - pass it to the ingredient. |
972 | | pRequester->ContentArrived((const unsigned char *)text.data(), text.size(), this); |
| 979 | QByteArray text; |
| 980 | if (m_Context->GetCarouselData(csPath, text)) |
| 981 | { |
| 982 | // If the content is not recognized catch the exception and continue |
| 983 | try |
| 984 | { |
| 985 | pRequester->ContentArrived( |
| 986 | reinterpret_cast< const unsigned char * >(text.constData()), |
| 987 | text.size(), this); |
| 988 | } |
| 989 | catch (char const *) |
| 990 | {} |
| 991 | } |
| 992 | else |
| 993 | { |
| 994 | MHLOG(MHLogWarning, QString("WARN No file content %1 <= %2") |
| 995 | .arg(pRequester->m_ObjectReference.Printable()).arg(csPath)); |
| 996 | EngineEvent(3); // ContentRefError |
| 997 | } |
973 | 998 | } |
974 | 999 | else |
975 | 1000 | { |
… |
… |
void MHEngine::CheckContentRequests() |
1023 | 1048 | // If the content is not recognized catch the exception and continue |
1024 | 1049 | try |
1025 | 1050 | { |
1026 | | MHLOG(MHLogLinks, QString("CheckContentRequests %1 arrived") |
1027 | | .arg(pContent->m_FileName)); |
1028 | | pContent->m_pRequester->ContentArrived((const unsigned char *)text.data(), |
1029 | | text.size(), this); |
| 1051 | MHLOG(MHLogNotifications, QString("Received %1 len %2") |
| 1052 | .arg(pContent->m_pRequester->m_ObjectReference.Printable()) |
| 1053 | .arg(text.size()) ); |
| 1054 | pContent->m_pRequester->ContentArrived( |
| 1055 | reinterpret_cast< const unsigned char * >(text.constData()), |
| 1056 | text.size(), this); |
1030 | 1057 | } |
1031 | 1058 | catch (char const *) |
1032 | 1059 | { |