From 914fc339749a5d625bc0aa6367cb1c950df7702b Mon Sep 17 00:00:00 2001 From: Jasmin Jessich Date: Sun, 18 Jun 2017 02:13:40 +0200 Subject: Protect stored timers in SortedTimers list - SortedTimers::GetByTimerId will now return "const cTimer *" to be sure the timer is never modified within live. Modifying or more worse deleting such a timer can lead to a segfault. This is no longer the case, but using const may protect future mistakes. --- pages/edit_timer.ecpp | 2 +- pages/timers.ecpp | 2 +- timers.cpp | 8 ++++---- timers.h | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pages/edit_timer.ecpp b/pages/edit_timer.ecpp index 24bd022..a466ef6 100644 --- a/pages/edit_timer.ecpp +++ b/pages/edit_timer.ecpp @@ -48,7 +48,7 @@ string edit_timerreferer; TimerConflictNotifier timerNotifier; <%request scope="page"> -cTimer* timer; +const cTimer* timer; <%include>page_init.eh <%cpp> diff --git a/pages/timers.ecpp b/pages/timers.ecpp index 91986dd..7b7bdc3 100644 --- a/pages/timers.ecpp +++ b/pages/timers.ecpp @@ -23,7 +23,7 @@ static const size_t maximumDescriptionLength = 300; bool logged_in(false); <%request scope="page"> - cTimer* timer; + const cTimer* timer; TimerConflictNotifier timerNotifier; <%include>page_init.eh diff --git a/timers.cpp b/timers.cpp index bb31ac8..d280a27 100644 --- a/timers.cpp +++ b/timers.cpp @@ -39,7 +39,7 @@ namespace vdrlive { return builder.str(); } - cTimer* SortedTimers::GetByTimerId( string const& timerid ) + const cTimer* SortedTimers::GetByTimerId( string const& timerid ) { vector< string > parts = StringSplit( timerid, ':' ); if ( parts.size() < 5 ) { @@ -181,7 +181,7 @@ namespace vdrlive { { } - void TimerManager::UpdateTimer( cTimer* timer, int flags, tChannelID& channel, string const& weekdays, string const& day, + void TimerManager::UpdateTimer( const cTimer* timer, int flags, tChannelID& channel, string const& weekdays, string const& day, int start, int stop, int priority, int lifetime, string const& title, string const& aux ) { cMutexLock lock( this ); @@ -220,7 +220,7 @@ namespace vdrlive { throw HtmlError( error ); } - void TimerManager::DelTimer( cTimer* timer ) + void TimerManager::DelTimer( const cTimer* timer ) { cMutexLock lock( this ); @@ -234,7 +234,7 @@ namespace vdrlive { throw HtmlError( error ); } - void TimerManager::ToggleTimerActive( cTimer* timer) + void TimerManager::ToggleTimerActive( const cTimer* timer) { cMutexLock lock( this ); diff --git a/timers.h b/timers.h index 1fc86ff..30583f3 100644 --- a/timers.h +++ b/timers.h @@ -15,7 +15,7 @@ namespace vdrlive { public: static std::string GetTimerId(cTimer const& timer); - cTimer* GetByTimerId(std::string const& timerid); + const cTimer* GetByTimerId(std::string const& timerid); // en- or decodes a timer into an id usable for DOM Ids. static std::string EncodeDomId(std::string const& timerid); @@ -53,11 +53,11 @@ namespace vdrlive { public: SortedTimers& GetTimers() { return m_timers; } - void UpdateTimer( cTimer* timer, int flags, tChannelID& channel, std::string const& weekdays, std::string const& day, + void UpdateTimer( const cTimer* timer, int flags, tChannelID& channel, std::string const& weekdays, std::string const& day, int start, int stop, int priority, int lifetime, std::string const& title, std::string const& aux ); - void DelTimer( cTimer* timer); - void ToggleTimerActive( cTimer* timer); + void DelTimer( const cTimer* timer); + void ToggleTimerActive( const cTimer* timer); // may only be called from Plugin::MainThreadHook void DoPendingWork(); void DoReloadTimers() { m_timers.ReloadTimers(); m_reloadTimers = false; } @@ -65,7 +65,7 @@ namespace vdrlive { void SetReloadTimers() { m_reloadTimers = true; } private: - typedef std::pair< cTimer*, std::string > TimerPair; + typedef std::pair< const cTimer*, std::string > TimerPair; typedef std::pair< TimerPair, std::string > ErrorPair; typedef std::list< TimerPair > TimerList; typedef std::list< ErrorPair > ErrorList; -- cgit v1.2.3