From 739dd819818b1550d1db075bb78191eeead136d6 Mon Sep 17 00:00:00 2001 From: Alex Kremer Date: Tue, 8 Nov 2022 15:42:02 +0100 Subject: [PATCH] Return correct error on subscription to non-existing stream (#390) Fixes #353 --- src/rpc/handlers/Subscribe.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/rpc/handlers/Subscribe.cpp b/src/rpc/handlers/Subscribe.cpp index af8f8deed..053871558 100644 --- a/src/rpc/handlers/Subscribe.cpp +++ b/src/rpc/handlers/Subscribe.cpp @@ -18,17 +18,14 @@ static std::unordered_set validCommonStreams{ Status validateStreams(boost::json::object const& request) { - boost::json::array const& streams = request.at(JS(streams)).as_array(); - - for (auto const& stream : streams) + for (auto const& streams = request.at(JS(streams)).as_array(); + auto const& stream : streams) { if (!stream.is_string()) return Status{Error::rpcINVALID_PARAMS, "streamNotString"}; - std::string s = stream.as_string().c_str(); - - if (validCommonStreams.find(s) == validCommonStreams.end()) - return Status{Error::rpcINVALID_PARAMS, "invalidStream" + s}; + if (!validCommonStreams.contains(stream.as_string().c_str())) + return Status{Error::rpcSTREAM_MALFORMED}; } return OK;