Fix: solved stack smashing when creating StatusNotifierCommand.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 29 Jan 2012 16:45:40 +0000 (14:45 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 29 Jan 2012 17:44:40 +0000 (15:44 -0200)
- 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
src/link/linkstatus.h
src/link/statusnotifiercommand.h

index 3c5bab9..e63d82a 100644 (file)
@@ -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 )
         {
index dcd30e0..24f7830 100644 (file)
@@ -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;
 
index ee53194..7fecb8e 100644 (file)
@@ -22,6 +22,8 @@ on this file might be covered by the GNU General Public License.
 
 #include <string>
 
+#include <boost/scoped_ptr.hpp>
+
 //-----------------------------------------------------------------------------
 // StatusNotifierCommand
 //-----------------------------------------------------------------------------
@@ -56,4 +58,10 @@ private:
 
 };
 
+//-----------------------------------------------------------------------------
+// StatusNotifierCommandItem
+//-----------------------------------------------------------------------------
+
+typedef boost::scoped_ptr<StatusNotifierCommand> StatusNotifierCommandItem;
+
 #endif // STATUS_NOTIFIER_COMMAND_H