diff --git a/include/libnuraft/msg_type.hxx b/include/libnuraft/msg_type.hxx index dfdb2746..1f58ec9e 100644 --- a/include/libnuraft/msg_type.hxx +++ b/include/libnuraft/msg_type.hxx @@ -64,7 +64,7 @@ enum msg_type { inline bool ATTR_UNUSED is_valid_msg(msg_type type) { if ( type >= request_vote_request && - type <= other_response ) { + type <= custom_notification_response ) { return true; } return false; diff --git a/src/asio_service.cxx b/src/asio_service.cxx index dd99f645..a1fd31fe 100644 --- a/src/asio_service.cxx +++ b/src/asio_service.cxx @@ -47,11 +47,8 @@ limitations under the License. #include #include #include -#include #include -#include #include -#include #ifdef USE_BOOST_ASIO using namespace boost; @@ -382,9 +379,21 @@ class rpc_session // byte marker = header_->get_byte(); h_bs.pos(0); byte marker = h_bs.get_u8(); - if (marker == 0x1) { - // Means that this is RPC_RESP, shouldn't happen. - p_er("Wrong packet: expected REQ, got RESP"); + if (marker != 0x0) { + // Means that this is not RPC_REQ, shouldn't happen. + p_er("Wrong packet: expected REQ, got %u", marker); + + if (impl_->get_options().corrupted_msg_handler_) { + impl_->get_options().corrupted_msg_handler_(header_, nullptr); + } + + this->stop(); + return; + } + + msg_type m_type = (msg_type)h_bs.get_u8(); + if (!is_valid_msg(m_type)) { + p_er("Wrong message type: got %u", (uint8_t)m_type); if (impl_->get_options().corrupted_msg_handler_) { impl_->get_options().corrupted_msg_handler_(header_, nullptr);