Skip to content

Commit

Permalink
Change topic strings to not automaticaly alter slashes
Browse files Browse the repository at this point in the history
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 0d04bf4)
  • Loading branch information
jsiwek committed Apr 10, 2020
1 parent 9c7332c commit 7a559ba
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 30 deletions.
22 changes: 22 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@

1.2.7 | 2020-04-10 16:16:06 -0700

* Release v1.2.6

* 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.2.6 | 2020-03-09 13:11:25 -0700

* Release v1.2.6
Expand Down
37 changes: 36 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
Broker 2.0.0
Broker 1.2.7
============

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.2.6
============

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.2.0
============

This release contains breaking API changes (for C++ code, not Python)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.6
1.2.7
3 changes: 1 addition & 2 deletions broker/topic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public:
>::type
>
topic(T&& x) : str_(std::forward<T>(x)) {
clean();
// nop
}

/// Appends a topic components with a separator.
Expand All @@ -62,7 +62,6 @@ public:
}

private:
void clean();

std::string str_;
};
Expand Down
2 changes: 1 addition & 1 deletion broker/version.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using type = unsigned;

constexpr type major = 1;
constexpr type minor = 2;
constexpr type patch = 6;
constexpr type patch = 7;
constexpr auto suffix = "";

constexpr type protocol = 2;
Expand Down
13 changes: 0 additions & 13 deletions src/topic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
11 changes: 0 additions & 11 deletions tests/cpp/topic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ auto sep = std::string{topic::sep};

} // namespace <anonymous>

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";
Expand Down
2 changes: 1 addition & 1 deletion tests/python/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit 7a559ba

Please sign in to comment.