From 7daed63cbc08a09da10593e1678c63a6fb5438ed Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 10 Apr 2020 14:28:14 -0700 Subject: [PATCH] Change topic strings to not automaticaly alter slashes Automatically removing trailing or consecutive slashes in topic strings prevents uniquely targeting topic names to a node. For example, publishing to "node-10/" should not match a subscription for "node-1/", but that's what happens with prefix-based matching if the trailing slash is automatically removed. (cherry picked from commit 0d04bf43131ade7000506711cbe43c068dab2471) --- CHANGES | 24 +++++++++++++++++++++++- NEWS | 35 +++++++++++++++++++++++++++++++++++ VERSION | 2 +- include/broker/topic.hh | 3 +-- include/broker/version.hh | 2 +- src/topic.cc | 13 ------------- tests/cpp/topic.cc | 11 ----------- tests/python/topic.py | 2 +- 8 files changed, 62 insertions(+), 30 deletions(-) diff --git a/CHANGES b/CHANGES index f57d4223..cc4f3f42 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,29 @@ +1.3.2 | 2020-04-10 16:22:15 -0700 + + * Release 1.3.2. + + * Change topic strings to not automaticaly alter slashes (Jon Siwek, Corelight) + + Automatically removing trailing or consecutive slashes in topic strings + prevents uniquely targeting topic names to a node. + + For example, publishing to "node-10/" should not match a subscription + for "node-1/", but that's what happens with prefix-based matching if the + trailing slash is automatically removed. + + * Add Cirrus CI config and remove Travis CI config (Jon Siwek, Corelight) + + The CMake configuration also now prefers choosing a Python3 installation + over Python2 (since that's end-of-life) for building the Broker Python + bindings. + + Some timeout values in unit tests were also fiddled to work better in + the CI environment. + 1.3.1 | 2020-03-09 13:02:50 -0700 - * Release 1.3.0. + * Release 1.3.1. * Fix a race condition in data store flare operations (Jon Siwek, Corelight) diff --git a/NEWS b/NEWS index ae25746a..064db295 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,38 @@ +Broker 1.3.2 +============ + +Change topic strings to not automatically alter slashes + +Automatically removing trailing or consecutive slashes in topic strings +prevents uniquely targeting topic names to a node. + +For example, publishing to "node-10/" should not match a subscription +for "node-1/", but that's what happens with prefix-based matching if the +trailing slash is automatically removed + +Broker 1.3.1 +============ + +Fix a race condition in data store flare operations + +The race (as seen via Zeek usage) goes like: + +Thread A: enqueue item, get suspended +Thread B: sees mailbox has items +Thread B: dequeue item +Thread B: extinguish flare +Thread A: resume, fire flare + +That ordering can leave the flare in an active state without any actual +items remaining in the mailbox. + +This patch adds a mutex/lock such that extinguishing of the flare cannot +be interleaved between the enqueue and firing of the flare. + +This likely relates to https://github.com/zeek/zeek/issues/838, +https://github.com/zeek/zeek/issues/716, as well as this thread +http://mailman.icsi.berkeley.edu/pipermail/zeek/2020-February/015062.html + Broker 1.3.0 ============ diff --git a/VERSION b/VERSION index 3a3cd8cc..1892b926 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.1 +1.3.2 diff --git a/include/broker/topic.hh b/include/broker/topic.hh index 41cda90c..65adf77c 100644 --- a/include/broker/topic.hh +++ b/include/broker/topic.hh @@ -41,7 +41,7 @@ public: >::type > topic(T&& x) : str_(std::forward(x)) { - clean(); + // nop } /// Appends a topic components with a separator. @@ -61,7 +61,6 @@ public: } private: - void clean(); std::string str_; }; diff --git a/include/broker/version.hh b/include/broker/version.hh index 6203e200..0dd680d4 100644 --- a/include/broker/version.hh +++ b/include/broker/version.hh @@ -10,7 +10,7 @@ using type = unsigned; constexpr type major = 1; constexpr type minor = 3; -constexpr type patch = 1; +constexpr type patch = 2; constexpr auto suffix = ""; constexpr type protocol = 2; diff --git a/src/topic.cc b/src/topic.cc index 635ee21e..2636a53d 100644 --- a/src/topic.cc +++ b/src/topic.cc @@ -48,19 +48,6 @@ bool topic::prefix_of(const topic& t) const { && t.str_.compare(0, str_.size(), str_) == 0; } -void topic::clean() { - // Remove one or more separators at the end. - while (!str_.empty() && str_.back() == sep) - str_.pop_back(); - // Replace multiple consecutive separators with a single one. - static char sep2[] = {sep, sep}; - auto i = str_.find(sep2, 0, sizeof(sep2)); - if (i != std::string::npos) { - auto j = str_.find_first_not_of(sep, i); - str_.replace(i, j - i, 1, sep); - } -} - bool operator==(const topic& lhs, const topic& rhs) { return lhs.string() == rhs.string(); } diff --git a/tests/cpp/topic.cc b/tests/cpp/topic.cc index 7b9d9e01..9b77dd64 100644 --- a/tests/cpp/topic.cc +++ b/tests/cpp/topic.cc @@ -12,17 +12,6 @@ auto sep = std::string{topic::sep}; } // namespace -TEST(cleaning) { - auto sep3 = sep + sep + sep; - CHECK_EQUAL(topic{sep3}, ""_t); - auto t = topic{"foo" + sep3}; - CHECK_EQUAL(t, "foo"); - t = sep3 + "foo"; - CHECK_EQUAL(t, sep + "foo"); - t = sep3 + "foo" + sep3; - CHECK_EQUAL(t, sep + "foo"); -} - TEST(concatenation) { topic t; t /= "foo"; diff --git a/tests/python/topic.py b/tests/python/topic.py index a9bc11b2..f408a77a 100644 --- a/tests/python/topic.py +++ b/tests/python/topic.py @@ -15,7 +15,7 @@ def test_append(self): t3 = t1 / t2 t2 /= t1 - self.assertEqual(t3.string(), "/a/b/c") + self.assertEqual(t3.string(), "/a//b/c") self.assertEqual(t2.string(), "/b/c/a") if __name__ == '__main__':