From 55a4be45520177acb809b6b58f36a16bff3ab739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matti=20Lehtim=C3=A4ki?= Date: Sat, 23 Aug 2014 09:59:54 +0200 Subject: Fix crash when cloning to a non-existent channel, thanks to Guy Martin. Automatically disable the cloning which causes an error. --- epgclone.c | 17 ++++++++++++++--- tools.c | 19 +++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/epgclone.c b/epgclone.c index 4c7b28e..46397d1 100644 --- a/epgclone.c +++ b/epgclone.c @@ -48,11 +48,22 @@ void cEpgClone::CloneEvent(cEvent *Source, cEvent *Dest) { if (Source->Seen()) Dest->SetSeen(); tChannelID channelID; - if (dest_num) - channelID = Channels.GetByNumber(dest_num)->GetChannelID(); + if (dest_num) { + cChannel *dest_chan = Channels.GetByNumber(dest_num); + if (dest_chan) + channelID = Channels.GetByNumber(dest_num)->GetChannelID(); + else + channelID = tChannelID::InvalidID; + } else channelID = tChannelID::FromString(dest_str); - AddEvent(Dest, channelID); + if (channelID == tChannelID::InvalidID) { + enabled = false; + delete Dest; + error("Destination channel %s not found for cloning, disabling cloning!", (dest_num ? *itoa(dest_num) : dest_str)); + } + else + AddEvent(Dest, channelID); } bool cEpgClone::Apply(cEvent *Event) diff --git a/tools.c b/tools.c index 0494166..843a29c 100644 --- a/tools.c +++ b/tools.c @@ -469,13 +469,20 @@ void cAddEventThread::Action(void) cSchedules *schedules = (cSchedules *)cSchedules::Schedules(SchedulesLock); Lock(); while (schedules && (e = list->First()) != NULL) { - cSchedule *schedule = (cSchedule *)schedules->GetSchedule(Channels.GetByChannelID(e->GetChannelID()), true); - if (schedule) { - schedule->AddEvent(e->GetEvent()); - EpgHandlers.SortSchedule(schedule); - EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); - list->Del(e); + tChannelID chanid = e->GetChannelID(); + cChannel *chan = Channels.GetByChannelID(chanid); + if (!chan) { + error("Destination channel %s not found for cloning!", *chanid.ToString()); } + else { + cSchedule *schedule = (cSchedule *)schedules->GetSchedule(chan, true); + if (schedule) { + schedule->AddEvent(e->GetEvent()); + EpgHandlers.SortSchedule(schedule); + EpgHandlers.DropOutdated(schedule, e->GetEvent()->StartTime(), e->GetEvent()->EndTime(), e->GetEvent()->TableID(), e->GetEvent()->Version()); + } + } + list->Del(e); } Unlock(); cCondWait::SleepMs(10); -- cgit v1.2.3