From c2dbcf0c046d50a8b53a6c2d9b522c201f17a338 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Wed, 12 Aug 2020 21:57:33 +0200 Subject: [PATCH] Refuse wildcards when publishing --- src/TopicTree.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/TopicTree.h b/src/TopicTree.h index e50ca78..0b945b3 100644 --- a/src/TopicTree.h +++ b/src/TopicTree.h @@ -129,10 +129,22 @@ private: drain(); } + /* Iterate over all segments in given topic */ for (; stop != std::string::npos; start = stop + 1) { stop = topic.find('/', start); std::string_view segment = topic.substr(start, stop - start); + /* It is very important to disallow wildcards when publishing. + * We will not catch EVERY misuse this lazy way, but enough to hinder + * explosive recursion. + * Terminating wildcards MAY still get triggered along the way, if for + * instace the error is found late while iterating the topic segments. */ + if (segment.length() == 1) { + if (segment[0] == '+' || segment[0] == '#') { + return; + } + } + /* Do we have a terminating wildcard child? */ if (iterator->terminatingWildcardChild) { iterator->terminatingWildcardChild->messages[messageId] = message;