Ticket #5089: libs_libmythfreemheg_Stream.cpp-check-for-null.patch

File libs_libmythfreemheg_Stream.cpp-check-for-null.patch, 3.2 KB (added by Erik Hovland <erik@…>, 12 years ago)

check multiplex pointer before dereferencing.

  • libs/libmythfreemheg/Stream.cpp

    
    From: Erik Hovland <erik@hovland.org>
    
    
    ---
    
     libs/libmythfreemheg/Stream.cpp |   42 +++++++++++++++++++++------------------
     1 files changed, 23 insertions(+), 19 deletions(-)
    
    diff --git a/libs/libmythfreemheg/Stream.cpp b/libs/libmythfreemheg/Stream.cpp
    index f88899c..9dda175 100644
    a b void MHStream::Initialise(MHParseNode *p, MHEngine *engine) 
    4040{
    4141    MHPresentable::Initialise(p, engine);
    4242    MHParseNode *pMultiplex = p->GetNamedArg(C_MULTIPLEX);
    43     for (int i = 0; i < pMultiplex->GetArgCount(); i++) {
    44         MHParseNode *pItem = pMultiplex->GetArgN(i);
    45         if (pItem->GetTagNo() == C_AUDIO) {
    46             MHAudio *pAudio = new MHAudio;
    47             m_Multiplex.Append(pAudio);
    48             pAudio->Initialise(pItem, engine);
     43    if (pMultiplex) {
     44        for (int i = 0; i < pMultiplex->GetArgCount(); i++) {
     45            MHParseNode *pItem = pMultiplex->GetArgN(i);
     46            if (pItem->GetTagNo() == C_AUDIO) {
     47                MHAudio *pAudio = new MHAudio;
     48                m_Multiplex.Append(pAudio);
     49                pAudio->Initialise(pItem, engine);
     50            }
     51            else if (pItem->GetTagNo() == C_VIDEO) {
     52                MHVideo *pVideo = new MHVideo;
     53                m_Multiplex.Append(pVideo);
     54                pVideo->Initialise(pItem, engine);
     55            }
     56            else if (pItem->GetTagNo() == C_RTGRAPHICS) {
     57                MHRTGraphics *pRtGraph = new MHRTGraphics;
     58                m_Multiplex.Append(pRtGraph);
     59                pRtGraph->Initialise(pItem, engine);
     60            }
     61            // Ignore unknown items
    4962        }
    50         else if (pItem->GetTagNo() == C_VIDEO) {
    51             MHVideo *pVideo = new MHVideo;
    52             m_Multiplex.Append(pVideo);
    53             pVideo->Initialise(pItem, engine);
    54         }
    55         else if (pItem->GetTagNo() == C_RTGRAPHICS) {
    56             MHRTGraphics *pRtGraph = new MHRTGraphics;
    57             m_Multiplex.Append(pRtGraph);
    58             pRtGraph->Initialise(pItem, engine);
    59         }
    60         // Ignore unknown items
    6163    }
    6264    MHParseNode *pStorage = p->GetNamedArg(C_STORAGE);
    6365    if (pStorage) m_nStorage = (enum Storage) pStorage->GetArgN(0)->GetEnumValue();
    MHAudio::MHAudio() 
    150152void MHAudio::Initialise(MHParseNode *p, MHEngine *engine)
    151153{
    152154    MHPresentable::Initialise(p, engine);
    153     m_nComponentTag = p->GetNamedArg(C_COMPONENT_TAG)->GetArgN(0)->GetIntValue();
     155    MHParseNode *pComponentTagNode =  p->GetNamedArg(C_COMPONENT_TAG);
     156    if (pComponentTagNode) m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue();
    154157    MHParseNode *pOrigVol = p->GetNamedArg(C_ORIGINAL_VOLUME);
    155158    if (pOrigVol) m_nOriginalVol = pOrigVol->GetIntValue();
    156159}
    MHVideo::MHVideo() 
    232235void MHVideo::Initialise(MHParseNode *p, MHEngine *engine)
    233236{
    234237    MHVisible::Initialise(p, engine);
    235     m_nComponentTag = p->GetNamedArg(C_COMPONENT_TAG)->GetArgN(0)->GetIntValue();
     238    MHParseNode *pComponentTagNode = p->GetNamedArg(C_COMPONENT_TAG);
     239    if (pComponentTagNode) m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue();
    236240    MHParseNode *pTerm = p->GetNamedArg(C_TERMINATION);
    237241    if (pTerm) m_Termination = (enum Termination)pTerm->GetEnumValue();
    238242}