Ticket #5575: mythphone-check-for-null.patch

File mythphone-check-for-null.patch, 12.7 KB (added by Erik Hovland <erik@…>, 17 years ago)

checks for null where necessary, before dereferencing

  • mythplugins/mythphone/mythphone/phoneui.cpp

    Fixes instances where an array should have been deleted but wasn't.
    
    From: Erik Hovland <erik@hovland.org>
    
    
    ---
    
     mythplugins/mythphone/mythphone/phoneui.cpp |    4 -
     mythplugins/mythphone/mythphone/sipfsm.cpp  |  140 ++++++++++++++++-----------
     2 files changed, 87 insertions(+), 57 deletions(-)
    
    diff --git a/mythplugins/mythphone/mythphone/phoneui.cpp b/mythplugins/mythphone/mythphone/phoneui.cpp
    index 58ca079..3c502ef 100644
    a b void PhoneUIBox::menuHistorySave(void)  
    13891389        CallRecord *crEntry =
    13901390            DirContainer->fetchCallRecordById(Current->getAttribute(1));
    13911391
    1392         DirEntry *entry =
    1393             DirContainer->FindMatchingDirectoryEntry(crEntry->getUri());
    13941392
    13951393        if (crEntry != 0)
    13961394        {
     1395            DirEntry *entry =
     1396                DirContainer->FindMatchingDirectoryEntry(crEntry->getUri());
    13971397            if (entry != 0)
    13981398            {
    13991399                // Tell the user one exists
  • mythplugins/mythphone/mythphone/sipfsm.cpp

    diff --git a/mythplugins/mythphone/mythphone/sipfsm.cpp b/mythplugins/mythphone/mythphone/sipfsm.cpp
    index 6ea457a..61ad11f 100644
    a b int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    17311731    switch (Event | State)
    17321732    {
    17331733    case SIP_IDLE_BYE:
    1734         BuildSendStatus(481, "BYE", sipMsg->getCSeqValue());
     1734        if (sipMsg != 0)
     1735            BuildSendStatus(481, "BYE", sipMsg->getCSeqValue());
    17351736        //481 Call/Transaction does not exist
    17361737        State = SIP_IDLE;
    17371738        break;
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    17391740    case SIP_IDLE_INVITESTATUS_2xx:
    17401741    case SIP_IDLE_INVITESTATUS_3456:
    17411742        // Check if we are being a proxy
    1742         if (sipMsg->getViaIp() == sipLocalIP)
     1743        if (sipMsg != 0 && sipMsg->getViaIp() == sipLocalIP)
    17431744        {
    17441745            ForwardMessage(sipMsg);
    17451746            State = SIP_IDLE;
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    17721773        State = SIP_OCONNECTING1;
    17731774        break;
    17741775    case SIP_IDLE_INVITE:
    1775         cseq = sipMsg->getCSeqValue();
     1776        if (sipMsg != 0)
     1777            cseq = sipMsg->getCSeqValue();
    17761778#ifdef SIPREGISTRAR
    1777         if ((toUrl->getUser() == sipUsername)) &&
     1779        if ((toUrl->getUser() == sipUsername) &&
    17781780            (toUrl->getHost() ==  "Volkaerts"))
    17791781#endif
    17801782        {
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    17821784            if (parent->numCalls() > 1)
    17831785            {
    17841786                // 486 Busy Here
    1785                 BuildSendStatus(486, "INVITE", sipMsg->getCSeqValue());
     1787                if (sipMsg != 0)
     1788                    BuildSendStatus(486, "INVITE", sipMsg->getCSeqValue());
     1789
    17861790                State = SIP_DISCONNECTING;
    17871791            }
    17881792            else
    17891793            {
    1790                 GetSDPInfo(sipMsg);
    1791                 // INVITE had a codec we support; proces
    1792                 if (audioPayloadIdx != -1)
    1793                 {
    1794                     AlertUser(sipMsg);
    1795                     BuildSendStatus(100, "INVITE", sipMsg->getCSeqValue(),
    1796                                     SIP_OPT_CONTACT | SIP_OPT_TIMESTAMP);
    1797                     // 100 Trying
    1798                     BuildSendStatus(180, "INVITE", sipMsg->getCSeqValue(),
    1799                                     SIP_OPT_CONTACT); //180 Ringing
    1800                     State = SIP_ICONNECTING;
    1801                 }
    1802                 else
     1794                if (sipMsg != 0)
    18031795                {
    1804                     BuildSendStatus(488, "INVITE", sipMsg->getCSeqValue());
    1805                     // 488 Not Acceptable Here
    1806                     State = SIP_DISCONNECTING;
     1796                    GetSDPInfo(sipMsg);
     1797
     1798                    // INVITE had a codec we support; proces
     1799                    if (audioPayloadIdx != -1)
     1800                    {
     1801                        AlertUser(sipMsg);
     1802                        BuildSendStatus(100, "INVITE", sipMsg->getCSeqValue(),
     1803                                        SIP_OPT_CONTACT | SIP_OPT_TIMESTAMP);
     1804                        // 100 Trying
     1805                        BuildSendStatus(180, "INVITE", sipMsg->getCSeqValue(),
     1806                                        SIP_OPT_CONTACT); //180 Ringing
     1807                        State = SIP_ICONNECTING;
     1808                    }
     1809                    else
     1810                    {
     1811                        BuildSendStatus(488, "INVITE", sipMsg->getCSeqValue());
     1812                        // 488 Not Acceptable Here
     1813                        State = SIP_DISCONNECTING;
     1814                    }
    18071815                }
    18081816            }
    18091817        }
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    18261834        break;
    18271835    case SIP_OCONNECTING1_INVITESTATUS_1xx:
    18281836        (parent->Timer())->Stop(this, SIP_RETX);
    1829         if ((sipMsg->getStatusCode() == 180) && (eventWindow))
    1830             QApplication::postEvent(
    1831                 eventWindow, new SipEvent(SipEvent::SipRingbackTone));
    1832         parent->SetNotification(
    1833             "CALLSTATUS", "", QString::number(sipMsg->getStatusCode()),
    1834             sipMsg->getReasonPhrase());
     1837        if (sipMsg != 0)
     1838        {
     1839            if ((sipMsg->getStatusCode() == 180) && (eventWindow))
     1840                QApplication::postEvent(
     1841                    eventWindow, new SipEvent(SipEvent::SipRingbackTone));
     1842
     1843            parent->SetNotification(
     1844                "CALLSTATUS", "", QString::number(sipMsg->getStatusCode()),
     1845                sipMsg->getReasonPhrase());
     1846        }
    18351847        State = SIP_OCONNECTING2;
    18361848        break;
    18371849    case SIP_OCONNECTING1_INVITESTATUS_3456:
    18381850        (parent->Timer())->Stop(this, SIP_RETX);
    1839         parent->SetNotification(
    1840             "CALLSTATUS", "", QString::number(sipMsg->getStatusCode()),
    1841             sipMsg->getReasonPhrase());
     1851        if (sipMsg != 0)
     1852            parent->SetNotification(
     1853                "CALLSTATUS", "", QString::number(sipMsg->getStatusCode()),
     1854                sipMsg->getReasonPhrase());
    18421855        // Fall through
    18431856    case SIP_OCONNECTING2_INVITESTATUS_3456:
    1844         if (((sipMsg->getStatusCode() == 407) ||
    1845              (sipMsg->getStatusCode() == 401)) &&
     1857        if (sipMsg != 0 && ((sipMsg->getStatusCode() == 407) ||
     1858                            (sipMsg->getStatusCode() == 401)) &&
    18461859            (viaRegProxy != 0) && (viaRegProxy->isRegistered()))
    18471860        {
    18481861            // Authentication Required
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    18621875        break;
    18631876
    18641877    case SIP_OCONNECTING2_INVITESTATUS_1xx:
    1865         if ((sipMsg->getStatusCode() == 180) && (eventWindow))
    1866             QApplication::postEvent(
    1867                 eventWindow, new SipEvent(SipEvent::SipRingbackTone));
    1868         parent->SetNotification(
    1869             "CALLSTATUS", "", QString::number(sipMsg->getStatusCode()),
    1870             sipMsg->getReasonPhrase());
     1878        if (sipMsg != 0)
     1879        {
     1880            if ((sipMsg->getStatusCode() == 180) && (eventWindow))
     1881                QApplication::postEvent(
     1882                    eventWindow, new SipEvent(SipEvent::SipRingbackTone));
     1883
     1884            parent->SetNotification(
     1885                "CALLSTATUS", "", QString::number(sipMsg->getStatusCode()),
     1886                sipMsg->getReasonPhrase());
     1887        }
    18711888        break;
    18721889
    18731890    case SIP_OCONNECTING1_INVITESTATUS_2xx:
    18741891        (parent->Timer())->Stop(this, SIP_RETX);
    18751892        // Fall through
    18761893    case SIP_OCONNECTING2_INVITESTATUS_2xx:
    1877         GetSDPInfo(sipMsg);
     1894        if (sipMsg != 0)
     1895            GetSDPInfo(sipMsg);
     1896
    18781897        if (audioPayloadIdx != -1) // INVITE had a codec we support; proces
    18791898        {
    18801899            BuildSendAck();
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    19561975        State = SIP_DISCONNECTING;
    19571976        break;
    19581977    case SIP_ICONNECTING_INVITE:
    1959         BuildSendStatus(180, "INVITE", sipMsg->getCSeqValue(),
    1960                         SIP_OPT_CONTACT); // Retxed INVITE, resend 180 Ringing
     1978        if (sipMsg != 0)
     1979            BuildSendStatus(180, "INVITE", sipMsg->getCSeqValue(),
     1980                            SIP_OPT_CONTACT); // Retxed INVITE, resend 180 Ringing
    19611981        break;
    19621982    case SIP_ICONNECTING_ANSWER:
    19631983        BuildSendStatus(200, "INVITE", cseq, SIP_OPT_SDP | SIP_OPT_CONTACT,
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    19761996                eventWindow, new SipEvent(SipEvent::SipCeaseAlertUser));
    19771997        }
    19781998    case SIP_ICONNECTING_WAITACK_CANCEL:
    1979         BuildSendStatus(200, "CANCEL", sipMsg->getCSeqValue()); // 200 Ok
     1999        if (sipMsg != 0)
     2000            BuildSendStatus(200, "CANCEL", sipMsg->getCSeqValue()); // 200 Ok
     2001
    19802002        State = SIP_IDLE;
    19812003        break;
    19822004    case SIP_ICONNECTING_WAITACK_ACK:
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    20282050        break;
    20292051    case SIP_CONNECTED_BYE:
    20302052        (parent->Timer())->Stop(this, SIP_RETX);
    2031         if (sipMsg->getCSeqValue() > cseq)
     2053        if (sipMsg != 0 && sipMsg->getCSeqValue() > cseq)
    20322054        {
    20332055            cseq = sipMsg->getCSeqValue();
    20342056            BuildSendStatus(200, "BYE", cseq); // 200 Ok
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    20392061            }
    20402062            State = SIP_IDLE;
    20412063        }
    2042         else
     2064        else if (sipMsg != 0)
    20432065        {
    20442066            // 400 Bad Request
    20452067            BuildSendStatus(400, "BYE", sipMsg->getCSeqValue());
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    20662088        break;
    20672089    case SIP_DISCONNECTING_CANCEL:
    20682090        (parent->Timer())->Stop(this, SIP_RETX);
    2069         BuildSendStatus(200, "CANCEL", sipMsg->getCSeqValue()); //200 Ok
     2091        if (sipMsg != 0)
     2092            BuildSendStatus(200, "CANCEL", sipMsg->getCSeqValue()); //200 Ok
     2093
    20702094        State = SIP_IDLE;
    20712095        break;
    20722096    case SIP_DISCONNECTING_BYESTATUS:
    20732097        (parent->Timer())->Stop(this, SIP_RETX);
    2074         if (((sipMsg->getStatusCode() == 407) ||
    2075              (sipMsg->getStatusCode() == 401)) &&
     2098        if (sipMsg != 0 && ((sipMsg->getStatusCode() == 407) ||
     2099                            (sipMsg->getStatusCode() == 401)) &&
    20762100            (viaRegProxy != 0) && (viaRegProxy->isRegistered()))
    20772101        {
    20782102            // Authentication Required
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    20842108        break;
    20852109    case SIP_DISCONNECTING_CANCELSTATUS:
    20862110        (parent->Timer())->Stop(this, SIP_RETX);
    2087         if (((sipMsg->getStatusCode() == 407) ||
    2088              (sipMsg->getStatusCode() == 401)) &&
     2111        if (sipMsg != 0 && ((sipMsg->getStatusCode() == 407) ||
     2112                            (sipMsg->getStatusCode() == 401)) &&
    20892113            (viaRegProxy != 0) && (viaRegProxy->isRegistered()))
    20902114        {
    20912115            // Authentication Required
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    20972121        break;
    20982122    case SIP_DISCONNECTING_BYE:
    20992123        (parent->Timer())->Stop(this, SIP_RETX);
    2100         BuildSendStatus(200, "BYE", sipMsg->getCSeqValue()); //200 Ok
     2124        if (sipMsg != 0)
     2125            BuildSendStatus(200, "BYE", sipMsg->getCSeqValue()); //200 Ok
     2126
    21012127        State = SIP_IDLE;
    21022128        break;
    21032129
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    21072133        State = SIP_CONNECT_MODIFYING1;
    21082134        break;
    21092135    case SIP_CONNECTED_INVITE:
    2110         GetSDPInfo(sipMsg);
     2136        if (sipMsg != 0)
     2137            GetSDPInfo(sipMsg);
     2138
    21112139        if (audioPayloadIdx != -1) // INVITE had a codec we support; proces
    21122140        {
    21132141            BuildSendStatus(200, "INVITE", cseq,
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    21152143                            BuildSdpResponse());
    21162144            State = SIP_CONNECT_MODIFYING2;
    21172145        }
    2118         else
     2146        else if (sipMsg != 0)
    21192147        {
    21202148            BuildSendStatus(488, "INVITE", sipMsg->getCSeqValue());
    21212149            // 488 Not Acceptable Here
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    21262154        break;
    21272155    case SIP_CONNMOD1_INVITESTATUS_2xx:
    21282156        (parent->Timer())->Stop(this, SIP_RETX);
    2129         GetSDPInfo(sipMsg);
     2157        if (sipMsg != 0)
     2158            GetSDPInfo(sipMsg);
     2159
    21302160        if (audioPayloadIdx != -1) // INVITE had a codec we support; proces
    21312161        {
    21322162            BuildSendAck();
    int SipCall::FSM(int Event, SipMsg *sipMsg, void *Value)  
    21572187        break;
    21582188    case SIP_CONNMOD1_INVITESTATUS_3456:
    21592189        (parent->Timer())->Stop(this, SIP_RETX);
    2160         if (((sipMsg->getStatusCode() == 407) ||
    2161              (sipMsg->getStatusCode() == 401)) &&
     2190        if (sipMsg != 0 && ((sipMsg->getStatusCode() == 407) ||
     2191                            (sipMsg->getStatusCode() == 401)) &&
    21622192            (viaRegProxy != 0) && (viaRegProxy->isRegistered()))
    21632193        {
    21642194            // Authentication Required