From c3f9b694548653a9c08b8706dc20f6795b8f8932 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 10 Feb 2024 16:13:37 -0500 Subject: [PATCH] catch and log certain situations where a buffer in a buffer vector may be released (this is likely due to a non-tread safe network flush); expose size of inclusion, exclusion and rewrite lists so we don't need to copy them to know the size; --- src/common/lookups/TalkgroupRulesLookup.h | 7 +++++++ src/common/network/udp/Socket.cpp | 7 +++++++ src/fne/network/fne/TagDMRData.cpp | 5 ++--- src/fne/network/fne/TagNXDNData.cpp | 5 ++--- src/fne/network/fne/TagP25Data.cpp | 5 ++--- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/common/lookups/TalkgroupRulesLookup.h b/src/common/lookups/TalkgroupRulesLookup.h index 8cf2c8b0..6687ee9c 100644 --- a/src/common/lookups/TalkgroupRulesLookup.h +++ b/src/common/lookups/TalkgroupRulesLookup.h @@ -195,6 +195,13 @@ namespace lookups return *this; } + /// Gets the count of inclusions. + uint8_t inclusionSize() const { return m_inclusion.size(); } + /// Gets the count of exclusions. + uint8_t exclusionSize() const { return m_exclusion.size(); } + /// Gets the count of rewrites. + uint8_t rewriteSize() const { return m_rewrite.size(); } + /// Return the YAML structure for this TalkgroupRuleConfig. void getYaml(yaml::Node &node) { diff --git a/src/common/network/udp/Socket.cpp b/src/common/network/udp/Socket.cpp index 3f312c8b..f291c3b4 100644 --- a/src/common/network/udp/Socket.cpp +++ b/src/common/network/udp/Socket.cpp @@ -511,7 +511,14 @@ bool Socket::write(BufferVector& buffers, ssize_t* lenWritten) noexcept bool skip = false; for (auto& buffer : buffers) { + if (buffer == nullptr) { + LogError(LOG_NET, "Socket::write() missing network buffer data? this isn't normal, aborting"); + skip = true; + break; + } + if (m_af != buffer->address.ss_family) { + LogError(LOG_NET, "Socket::write() mismatched network address family? this isn't normal, aborting"); skip = true; break; } diff --git a/src/fne/network/fne/TagDMRData.cpp b/src/fne/network/fne/TagDMRData.cpp index 27d74c00..37551d28 100644 --- a/src/fne/network/fne/TagDMRData.cpp +++ b/src/fne/network/fne/TagDMRData.cpp @@ -422,10 +422,9 @@ bool TagDMRData::peerRewrite(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo, tg = m_network->m_tidLookup->findByRewrite(peerId, dstId); } - std::vector rewrites = tg.config().rewrite(); - bool rewrote = false; - if (rewrites.size() > 0) { + if (tg.config().rewriteSize() > 0) { + std::vector rewrites = tg.config().rewrite(); for (auto entry : rewrites) { if (entry.peerId() == peerId) { if (outbound) { diff --git a/src/fne/network/fne/TagNXDNData.cpp b/src/fne/network/fne/TagNXDNData.cpp index 1bdb1838..09d0dbef 100644 --- a/src/fne/network/fne/TagNXDNData.cpp +++ b/src/fne/network/fne/TagNXDNData.cpp @@ -347,10 +347,9 @@ bool TagNXDNData::peerRewrite(uint32_t peerId, uint32_t& dstId, bool outbound) tg = m_network->m_tidLookup->findByRewrite(peerId, dstId); } - std::vector rewrites = tg.config().rewrite(); - bool rewrote = false; - if (rewrites.size() > 0) { + if (tg.config().rewriteSize() > 0) { + std::vector rewrites = tg.config().rewrite(); for (auto entry : rewrites) { if (entry.peerId() == peerId) { if (outbound) { diff --git a/src/fne/network/fne/TagP25Data.cpp b/src/fne/network/fne/TagP25Data.cpp index 0f41b80a..7829a9d7 100644 --- a/src/fne/network/fne/TagP25Data.cpp +++ b/src/fne/network/fne/TagP25Data.cpp @@ -485,9 +485,8 @@ bool TagP25Data::peerRewrite(uint32_t peerId, uint32_t& dstId, bool outbound) tg = m_network->m_tidLookup->findByRewrite(peerId, dstId); } - std::vector rewrites = tg.config().rewrite(); - - if (rewrites.size() > 0) { + if (tg.config().rewriteSize() > 0) { + std::vector rewrites = tg.config().rewrite(); for (auto entry : rewrites) { if (entry.peerId() == peerId) { if (outbound) {