diff --git a/src/Makefile.am b/src/Makefile.am index 1b33a20..4f70623 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,9 +25,7 @@ SUBDIRS = test AM_CXXFLAGS = -I$(srcdir) \ -I$(srcdir)/Murmur \ -I$(top_srcdir) \ - $(libmaxminddb_CFLAGS) \ - -std=c++0x \ - -Wall -Wno-parentheses -Wno-switch -Wno-sign-compare -Wno-char-subscripts + $(libmaxminddb_CFLAGS) bin_PROGRAMS = packetq diff --git a/src/sql.h b/src/sql.h index bcd9a80..0c68e5f 100644 --- a/src/sql.h +++ b/src/sql.h @@ -216,7 +216,7 @@ class Allocator { void add_buffer() { - m_curr_buffer = new Buffer(*this); + m_curr_buffer = new _Buffer(*this); m_buffers.push_back(m_curr_buffer); } T* allocate() @@ -243,28 +243,30 @@ class Allocator { } void deallocate(T* item) { - Buffer** buffptr = (Buffer**)item; + _Buffer** buffptr = (_Buffer**)item; buffptr[-1]->deallocate(item); } private: - class Buffer { + class _Buffer { private: - Buffer& operator=(const Buffer& other); - Buffer(Buffer&& other) noexcept; - Buffer const& operator=(Buffer&& other); + _Buffer& operator=(const _Buffer& other); + _Buffer(_Buffer&& other) noexcept; + _Buffer const& operator=(_Buffer&& other); public: friend class Allocator; - Buffer(Allocator& allocator) + _Buffer(Allocator& allocator) : m_allocator(allocator) { m_has_space = true; m_used = 0; - m_stride = (sizeof(Buffer*) + m_allocator.m_size); - m_memory = (char*)calloc(m_stride, m_allocator.m_buffersize); + m_stride = (sizeof(_Buffer*) + m_allocator.m_size); + // align size of m_stride to that of a pointer + m_stride = ((m_stride / sizeof(void*)) + 1) * sizeof(void*); + m_memory = (char*)calloc(m_stride, m_allocator.m_buffersize); } - ~Buffer() + ~_Buffer() { free(m_memory); } @@ -277,10 +279,10 @@ class Allocator { m_free_list.pop(); } if (!obj && m_used < m_allocator.m_buffersize) { - char* ptr = &m_memory[m_stride * m_used++]; - Buffer** b = (Buffer**)ptr; - *b = this; - obj = (T*)(&b[1]); + char* ptr = &m_memory[m_stride * m_used++]; + _Buffer** b = (_Buffer**)ptr; + *b = this; + obj = (T*)(&b[1]); } m_has_space = true; if (!obj) @@ -302,8 +304,8 @@ class Allocator { char* m_memory; }; - Buffer* m_curr_buffer; - std::list m_buffers; + _Buffer* m_curr_buffer; + std::list<_Buffer*> m_buffers; int m_buffersize; int m_size; @@ -452,7 +454,7 @@ class Table { std::vector m_text_column_offsets; }; -#define ROW_DUMMY_SIZE 4 +#define ROW_DUMMY_SIZE sizeof(void*) class Row { public: diff --git a/src/tcp.cpp b/src/tcp.cpp index 09ec9a7..5787e84 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -33,14 +33,6 @@ namespace packetq { class Stream_id { public: /// constructor - Stream_id() - : m_src_port(0) - , m_dst_port(0) - { - memset(&m_src_ip, 0, sizeof(m_src_ip)); - memset(&m_dst_ip, 0, sizeof(m_dst_ip)); - } - /// constructor taking source and destination adresses Stream_id(in6addr_t& src_ip, in6addr_t& dst_ip, unsigned short src_port, @@ -55,15 +47,7 @@ class Stream_id { /// < comparison operator for the std::map bool operator<(const Stream_id& rhs) const { - if (memcmp(&m_src_ip.__in6_u.__u6_addr8, &rhs.m_src_ip.__in6_u.__u6_addr8, sizeof(m_src_ip.__in6_u.__u6_addr8)) < 0) - return true; - if (memcmp(&m_dst_ip.__in6_u.__u6_addr8, &rhs.m_dst_ip.__in6_u.__u6_addr8, sizeof(m_dst_ip.__in6_u.__u6_addr8)) < 0) - return true; - if (m_src_port < rhs.m_src_port) - return true; - if (m_dst_port < rhs.m_dst_port) - return true; - return false; + return memcmp(this, &rhs, sizeof(*this)) < 0; } private: @@ -128,6 +112,10 @@ class Stream { m_nseq = false; m_seq = 0; } + ~Stream() + { + m_segments.clear(); + } /// add a datasegment to the stream /** If the segment has the expected sequence number * the segment will be added to the list @@ -255,7 +243,11 @@ assemble_tcp( data = 0; if (str.has_content()) { - int size = str.get_size(); + int size = str.get_size(); + if (size < 2) { + // need at least dnslen + return 0; + } unsigned char* buffer = str.get_buffer(); int dns_size = (int(buffer[0]) << 8) | buffer[1];