fixed bug: dumping packets leaked char array (dump file name) on heap
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 25 Feb 2015 15:00:21 +0000 (16:00 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 25 Feb 2015 15:00:21 +0000 (16:00 +0100)
src/icmp/icmppacketfactory.cpp
src/icmp/icmppacketfactory.h

index fe422bb..78163ce 100644 (file)
@@ -25,6 +25,7 @@
 #include <ctime>
 #include <iostream>
 #include <sstream>
+#include <boost/scoped_array.hpp>
 
 #include <logfunc.hpp>
 
@@ -77,8 +78,11 @@ void dump_packet(const std::string &data)
     temp_name << capture_time;
     temp_name << "_XXXXXX.pcap";
     std::string temp_str = temp_name.str();
-    char *secure_filename = strdup(temp_str.c_str());
-    int fd = mkstemps(secure_filename, 5);   // 5 = ".pcap".length
+    std::size_t temp_size = temp_str.size();
+    boost::scoped_array<char> secure_filename( new char[temp_size + 1] );
+    std::copy(temp_str.begin(), temp_str.end(), secure_filename.get());
+    secure_filename[temp_size] = '\0';
+    int fd = mkstemps(secure_filename.get(), 5);   // 5 = ".pcap".length
     if (fd == -1)
     {
         GlobalLogger.warning() << "Failed to create temp file!" << endl;
index 60483be..9991c74 100644 (file)
@@ -29,6 +29,9 @@
 
 #include "icmp/icmppacket.h"
 
+
+void dump_packet(const std::string &data);
+
 //-----------------------------------------------------------------------------
 // IcmpPacketFactory
 //-----------------------------------------------------------------------------