From 709ded826885d536ec58b6c7008e5239e8b87db1 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Sun, 29 Jan 2012 14:45:40 -0200 Subject: [PATCH] Fix: solved stack smashing when creating StatusNotifierCommand. - The StatusNotifierCommand member is a smart pointer instead of an object. - Stack smashing is a protection from GCC to avoid segmentation faults from buffer overruns. Use -fno-stack-protector to disable it. - This workaround protects some std::string strings from optimizations, which cause destructors to be called onto invalid std::string objects. Not sure whether is it a bug from gcc or in the pingcheck. --- src/link/linkstatus.cpp | 10 +++++----- src/link/linkstatus.h | 2 +- src/link/statusnotifiercommand.h | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/link/linkstatus.cpp b/src/link/linkstatus.cpp index 3c5bab9..e63d82a 100644 --- a/src/link/linkstatus.cpp +++ b/src/link/linkstatus.cpp @@ -63,7 +63,7 @@ LinkStatus::LinkStatus( CurrentLinkStatus( Status_Down ), CurrentNotificationStatus( NotificationStatus_NotReported ), TimeLinkStatusChanged( microsec_clock::universal_time() ), - StatusNotifierCmd( status_notifier_cmd ), + StatusNotifierCmd( new StatusNotifierCommand( status_notifier_cmd ) ), Mutex() { BOOST_ASSERT( 0 <= hosts_down_limit ); @@ -162,12 +162,12 @@ void LinkStatus::notify_link_up() BOOST_ASSERT( CurrentLinkStatus == Status_Up ); BOOST_ASSERT( CurrentNotificationStatus == NotificationStatus_NotReported ); - StatusNotifierCmd.set_token_value( + StatusNotifierCmd->set_token_value( StatusNotifierCommand::StatusToken, "up" ); //lint !e534 - bool executed = StatusNotifierCmd.execute(); + bool executed = StatusNotifierCmd->execute(); if ( executed ) { @@ -187,12 +187,12 @@ void LinkStatus::notify_link_down() BOOST_ASSERT( CurrentLinkStatus == Status_Down ); BOOST_ASSERT( CurrentNotificationStatus == NotificationStatus_NotReported ); - StatusNotifierCmd.set_token_value( + StatusNotifierCmd->set_token_value( StatusNotifierCommand::StatusToken, "down" ); //lint !e534 - bool executed = StatusNotifierCmd.execute(); + bool executed = StatusNotifierCmd->execute(); if ( executed ) { diff --git a/src/link/linkstatus.h b/src/link/linkstatus.h index dcd30e0..24f7830 100644 --- a/src/link/linkstatus.h +++ b/src/link/linkstatus.h @@ -98,7 +98,7 @@ private: /// When was the last time the status changed boost::posix_time::ptime TimeLinkStatusChanged; /// Command used to notify the status of the link - StatusNotifierCommand StatusNotifierCmd; + StatusNotifierCommandItem StatusNotifierCmd; /// Mutual exclusion variable to avoid data races boost::mutex Mutex; diff --git a/src/link/statusnotifiercommand.h b/src/link/statusnotifiercommand.h index ee53194..7fecb8e 100644 --- a/src/link/statusnotifiercommand.h +++ b/src/link/statusnotifiercommand.h @@ -22,6 +22,8 @@ on this file might be covered by the GNU General Public License. #include +#include + //----------------------------------------------------------------------------- // StatusNotifierCommand //----------------------------------------------------------------------------- @@ -56,4 +58,10 @@ private: }; +//----------------------------------------------------------------------------- +// StatusNotifierCommandItem +//----------------------------------------------------------------------------- + +typedef boost::scoped_ptr StatusNotifierCommandItem; + #endif // STATUS_NOTIFIER_COMMAND_H -- 1.7.1