Ticket #5236: libs_libmythfreemheg-check-for-null.patch

File libs_libmythfreemheg-check-for-null.patch, 9.5 KB (added by Erik Hovland <erik@…>, 13 years ago)

Fixes any instance in libmythfreemheg where a pointer could be null but is dereferenced before checking for null

  • libs/libmythfreemheg/Groups.cpp

    Make sure that the pointer is checked for null before dereferencing.
    
    From: Erik Hovland <erik@hovland.org>
    
    
    ---
    
     libs/libmythfreemheg/Groups.cpp     |    8 ++++---
     libs/libmythfreemheg/Link.cpp       |    2 +-
     libs/libmythfreemheg/Programs.cpp   |    4 +++
     libs/libmythfreemheg/Stream.cpp     |   42 +++++++++++++++++++----------------
     libs/libmythfreemheg/TokenGroup.cpp |   10 +++++---
     libs/libmythfreemheg/Variables.cpp  |   18 +++++++++------
     6 files changed, 49 insertions(+), 35 deletions(-)
    
    diff --git a/libs/libmythfreemheg/Groups.cpp b/libs/libmythfreemheg/Groups.cpp
    index a65c465..2240366 100644
    a b void MHScene::Initialise(MHParseNode *p, MHEngine *engine) 
    398398    MHGroup::Initialise(p, engine);
    399399    // Event register.
    400400    MHParseNode *pInputEventReg = p->GetNamedArg(C_INPUT_EVENT_REGISTER);
    401     m_nEventReg = pInputEventReg->GetArgN(0)->GetIntValue();
     401    if (pInputEventReg) m_nEventReg = pInputEventReg->GetArgN(0)->GetIntValue();
    402402    // Co-ordinate system
    403403    MHParseNode *pSceneCoords = p->GetNamedArg(C_SCENE_COORDINATE_SYSTEM);
    404     m_nSceneCoordX = pSceneCoords->GetArgN(0)->GetIntValue();
    405     m_nSceneCoordY = pSceneCoords->GetArgN(1)->GetIntValue();
     404    if (pSceneCoords) {
     405        m_nSceneCoordX = pSceneCoords->GetArgN(0)->GetIntValue();
     406        m_nSceneCoordY = pSceneCoords->GetArgN(1)->GetIntValue();
     407    }
    406408    // Aspect ratio
    407409    MHParseNode *pAspectRatio = p->GetNamedArg(C_ASPECT_RATIO);
    408410    if (pAspectRatio) {
  • libs/libmythfreemheg/Link.cpp

    diff --git a/libs/libmythfreemheg/Link.cpp b/libs/libmythfreemheg/Link.cpp
    index daab860..30d0878 100644
    a b void MHLink::Initialise(MHParseNode *p, MHEngine *engine) 
    7373    }
    7474
    7575    MHParseNode *pLinkEffect = p->GetNamedArg(C_LINK_EFFECT);
    76     m_LinkEffect.Initialise(pLinkEffect, engine);
     76    if (pLinkEffect) m_LinkEffect.Initialise(pLinkEffect, engine);
    7777}
    7878
    7979static const char *rchEventType[] =
  • libs/libmythfreemheg/Programs.cpp

    diff --git a/libs/libmythfreemheg/Programs.cpp b/libs/libmythfreemheg/Programs.cpp
    index 8895d21..0dd4fa4 100644
    a b MHProgram::MHProgram() 
    5050void MHProgram::Initialise(MHParseNode *p, MHEngine *engine)
    5151{
    5252    MHIngredient::Initialise(p, engine);
    53     p->GetNamedArg(C_NAME)->GetArgN(0)->GetStringValue(m_Name); // Program name
     53    MHParseNode *pCmdNode = p->GetNamedArg(C_NAME);
     54    if (pCmdNode) pCmdNode->GetArgN(0)->GetStringValue(m_Name); // Program name
     55
    5456    MHParseNode *pAvail = p->GetNamedArg(C_INITIALLY_AVAILABLE);
    5557    if (pAvail) m_fInitiallyAvailable = pAvail->GetArgN(0)->GetBoolValue();
    5658    // The MHEG Standard says that InitiallyAvailable is mandatory and should be false.
  • libs/libmythfreemheg/Stream.cpp

    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}
  • libs/libmythfreemheg/TokenGroup.cpp

    diff --git a/libs/libmythfreemheg/TokenGroup.cpp b/libs/libmythfreemheg/TokenGroup.cpp
    index c3f0005..3576c36 100644
    a b void MHListGroup::Initialise(MHParseNode *p, MHEngine *engine) 
    231231{
    232232    MHTokenGroup::Initialise(p, engine);
    233233    MHParseNode *pPositions = p->GetNamedArg(C_POSITIONS);
    234     for (int i = 0; i < pPositions->GetArgCount(); i++) {
    235         MHParseNode *pPos = pPositions->GetArgN(i);
    236         QPoint pos(pPos->GetSeqN(0)->GetIntValue(), pPos->GetSeqN(1)->GetIntValue());
    237         m_Positions.Append(pos);
     234    if (pPositions) {
     235        for (int i = 0; i < pPositions->GetArgCount(); i++) {
     236            MHParseNode *pPos = pPositions->GetArgN(i);
     237            QPoint pos(pPos->GetSeqN(0)->GetIntValue(), pPos->GetSeqN(1)->GetIntValue());
     238            m_Positions.Append(pos);
     239        }
    238240    }
    239241    MHParseNode *pWrap = p->GetNamedArg(C_WRAP_AROUND);
    240242    if (pWrap) m_fWrapAround = pWrap->GetArgN(0)->GetBoolValue();
  • libs/libmythfreemheg/Variables.cpp

    diff --git a/libs/libmythfreemheg/Variables.cpp b/libs/libmythfreemheg/Variables.cpp
    index 14ea9d6..da813c5 100644
    a b void MHBooleanVar::Initialise(MHParseNode *p, MHEngine *engine) 
    5757    MHVariable::Initialise(p, engine);
    5858    // Original value should be a bool.
    5959    MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
    60     m_fOriginalValue = pInitial->GetArgN(0)->GetBoolValue();
     60    if (pInitial) m_fOriginalValue = pInitial->GetArgN(0)->GetBoolValue();
    6161}
    6262
    6363void MHBooleanVar::PrintMe(FILE *fd, int nTabs) const
    void MHIntegerVar::Initialise(MHParseNode *p, MHEngine *engine) 
    111111    MHVariable::Initialise(p, engine);
    112112    // Original value should be an int.
    113113    MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
    114     m_nOriginalValue = pInitial->GetArgN(0)->GetIntValue();
     114    if (pInitial) m_nOriginalValue = pInitial->GetArgN(0)->GetIntValue();
    115115}
    116116
    117117void MHIntegerVar::PrintMe(FILE *fd, int nTabs) const
    void MHOctetStrVar::Initialise(MHParseNode *p, MHEngine *engine) 
    185185    MHVariable::Initialise(p, engine);
    186186    // Original value should be a string.
    187187    MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
    188     pInitial->GetArgN(0)->GetStringValue(m_OriginalValue);
     188    if (pInitial) pInitial->GetArgN(0)->GetStringValue(m_OriginalValue);
    189189}
    190190
    191191void MHOctetStrVar::PrintMe(FILE *fd, int nTabs) const
    void MHObjectRefVar::Initialise(MHParseNode *p, MHEngine *engine) 
    258258    // Original value should be an object reference.
    259259    MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
    260260    // and this should be a ObjRef node.
    261     MHParseNode *pArg = pInitial->GetNamedArg(C_OBJECT_REFERENCE);
    262     m_OriginalValue.Initialise(pArg->GetArgN(0), engine);
     261    if (pInitial) {
     262        MHParseNode *pArg = pInitial->GetNamedArg(C_OBJECT_REFERENCE);
     263        if (pArg) m_OriginalValue.Initialise(pArg->GetArgN(0), engine);
     264    }
    263265}
    264266
    265267void MHObjectRefVar::PrintMe(FILE *fd, int nTabs) const
    void MHContentRefVar::Initialise(MHParseNode *p, MHEngine *engine) 
    312314    // Original value should be a content reference.
    313315    MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE);
    314316    // and this should be a ContentRef node.
    315     MHParseNode *pArg = pInitial->GetNamedArg(C_CONTENT_REFERENCE);
    316     m_OriginalValue.Initialise(pArg->GetArgN(0), engine);
     317    if (pInitial) {
     318        MHParseNode *pArg = pInitial->GetNamedArg(C_CONTENT_REFERENCE);
     319        if (pArg) m_OriginalValue.Initialise(pArg->GetArgN(0), engine);
     320    }
    317321}
    318322
    319323void MHContentRefVar::PrintMe(FILE *fd, int nTabs) const