From a92bd1ca7678cba6fc8fc1bd356e142d6e0e5afa Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Wed, 25 Feb 2015 16:00:21 +0100 Subject: [PATCH] fixed bug: dumping packets leaked char array (dump file name) on heap --- src/icmp/icmppacketfactory.cpp | 8 ++++++-- src/icmp/icmppacketfactory.h | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/icmp/icmppacketfactory.cpp b/src/icmp/icmppacketfactory.cpp index fe422bb..78163ce 100644 --- a/src/icmp/icmppacketfactory.cpp +++ b/src/icmp/icmppacketfactory.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -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 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; diff --git a/src/icmp/icmppacketfactory.h b/src/icmp/icmppacketfactory.h index 60483be..9991c74 100644 --- a/src/icmp/icmppacketfactory.h +++ b/src/icmp/icmppacketfactory.h @@ -29,6 +29,9 @@ #include "icmp/icmppacket.h" + +void dump_packet(const std::string &data); + //----------------------------------------------------------------------------- // IcmpPacketFactory //----------------------------------------------------------------------------- -- 1.7.1