From 83ae498008c60c9f6fdbdb5edceff0bd37a0fe65 Mon Sep 17 00:00:00 2001 From: Lucas Dias Date: Tue, 10 Dec 2024 21:11:25 -0300 Subject: [PATCH] Catch exception of DeserializeNodes Fix calls to DeserializeNodes. They must catch possible exceptions Signed-off-by: Lucas Dias --- src/network_engine.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/network_engine.cpp b/src/network_engine.cpp index d36a01e72..fd6b8c925 100644 --- a/src/network_engine.cpp +++ b/src/network_engine.cpp @@ -526,8 +526,13 @@ NetworkEngine::process(std::unique_ptr&& msg, const SockAddr& fro throw DhtProtocolException {DhtProtocolException::UNKNOWN_TID, "Can't find socket", msg->id}; node->received(now, {}); onNewNode(node, 2); - deserializeNodes(*msg, from); - rsocket->on_receive(node, std::move(*msg)); + try { + deserializeNodes(*msg, from); + rsocket->on_receive(node, std::move(*msg)); + } catch (const DhtProtocolException& e) { + if (logger_) + logger_->w("Can't deserialize nodes %s", e.what()); + } } else if (msg->type == MessageType::Error or msg->type == MessageType::Reply) { auto rsocket = node->getSocket(msg->tid); @@ -590,13 +595,22 @@ NetworkEngine::process(std::unique_ptr&& msg, const SockAddr& fro r.node->authSuccess(); } r.reply_time = scheduler.time(); - - deserializeNodes(*msg, from); - r.setDone(std::move(*msg)); + try { + deserializeNodes(*msg, from); + r.setDone(std::move(*msg)); + } catch (const DhtProtocolException& e) { + if (logger_) + logger_->w("Can't deserialize nodes %s", e.what()); + } break; } else { /* request socket data */ - deserializeNodes(*msg, from); - rsocket->on_receive(node, std::move(*msg)); + try { + deserializeNodes(*msg, from); + rsocket->on_receive(node, std::move(*msg)); + } catch (const DhtProtocolException& e) { + if (logger_) + logger_->w("Can't deserialize nodes %s", e.what()); + } } break; default: