diff --git a/.gitignore b/.gitignore
index 1f394ce..e7982cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,6 +63,7 @@ libtool
src/config.h
src/stamp-h1
build
+configure~
# Project specific files
src/packetq
diff --git a/CHANGES b/CHANGES
index d01d2f0..57a932c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,14 @@
+2024-09-04 Jerry Lundström
+
+ Release 1.7.3
+
+ This patch release fixes memory alignment issues and the handling of
+ TCP segments. Many thanks to Ray Bellis (ISC) for reporting this and
+ helping greatly with fixing it!
+
+ d8a06a3 C++11
+ 8c99466 Memory align, TCP assemble
+
2024-08-29 Jerry Lundström
Release 1.7.2
diff --git a/configure.ac b/configure.ac
index e17413b..b2fc9ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,13 +18,14 @@
# along with PacketQ. If not, see .
AC_PREREQ(2.61)
-AC_INIT([packetq], [1.7.2], [admin@dns-oarc.net], [packetq], [https://github.com/DNS-OARC/packetq/issues])
+AC_INIT([packetq], [1.7.3], [admin@dns-oarc.net], [packetq], [https://github.com/DNS-OARC/packetq/issues])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
AC_CONFIG_SRCDIR([src/packetq.cpp])
AC_CONFIG_HEADER([src/config.h])
# Checks for programs.
AC_PROG_CXX
+AS_VAR_APPEND(CXXFLAGS, [" -std=c++11"])
# Check --enable-warn-all
AC_ARG_ENABLE([warn-all], [AS_HELP_STRING([--enable-warn-all], [Enable all compiler warnings])], [
diff --git a/debian/changelog b/debian/changelog
index 4af6245..b2e70b2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,16 @@
+packetq (1.7.3-1~unstable+1) unstable; urgency=low
+
+ * Release 1.7.3
+
+ This patch release fixes memory alignment issues and the handling of
+ TCP segments. Many thanks to Ray Bellis (ISC) for reporting this and
+ helping greatly with fixing it!
+
+ d8a06a3 C++11
+ 8c99466 Memory align, TCP assemble
+
+ -- Jerry Lundström Wed, 04 Sep 2024 14:46:27 +0200
+
packetq (1.7.2-1~unstable+1) unstable; urgency=low
* Release 1.7.2
diff --git a/rpm/packetq.spec b/rpm/packetq.spec
index e03818d..c26e35e 100644
--- a/rpm/packetq.spec
+++ b/rpm/packetq.spec
@@ -1,5 +1,5 @@
Name: packetq
-Version: 1.7.2
+Version: 1.7.3
Release: 1%{?dist}
Summary: A tool that provides a basic SQL-frontend to PCAP-files
Group: Productivity/Networking/DNS/Utilities
@@ -56,6 +56,14 @@ rm -rf $RPM_BUILD_ROOT
%changelog
+* Wed Sep 04 2024 Jerry Lundström 1.7.3-1
+- Release 1.7.3
+ * This patch release fixes memory alignment issues and the handling of
+ TCP segments. Many thanks to Ray Bellis (ISC) for reporting this and
+ helping greatly with fixing it!
+ * Commits:
+ d8a06a3 C++11
+ 8c99466 Memory align, TCP assemble
* Thu Aug 29 2024 Jerry Lundström 1.7.2-1
- Release 1.7.2
* This patch release fixes various issues reported by CI/code analysis
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];