From 3a6f7e7d7d27866fca0c6476b3d5932d66ad0b9f Mon Sep 17 00:00:00 2001 From: modeco80 Date: Sun, 10 Mar 2024 06:17:43 -0400 Subject: [PATCH] Fix message parsing My bad lol --- src/DirtySockClient.cpp | 8 ++++++++ src/IMessage.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/DirtySockClient.cpp b/src/DirtySockClient.cpp index e43b690..756dc27 100644 --- a/src/DirtySockClient.cpp +++ b/src/DirtySockClient.cpp @@ -5,6 +5,8 @@ #include "DirtySockServer.hpp" +constexpr static auto MAX_PAYLOAD_SIZE = 4 * (1024 * 1024); + namespace ls { DirtySockClient::DirtySockClient(Stream stream, base::Ref server) @@ -26,6 +28,12 @@ namespace ls { try { co_await asio::async_read(stream, asio::buffer(&header, sizeof(header)), asio::deferred); + // Sanity check. I don't expect game payloa + if(header.payloadSize > MAX_PAYLOAD_SIZE) { + base::LogError("WOAH! Message size {} MB larger than {}MB..", (static_cast(header.payloadSize) / 1024 / 1024), (static_cast(MAX_PAYLOAD_SIZE) / 1024 / 1024)); + co_return nullptr; + } + propertyBuffer.resize(header.payloadSize); co_await asio::async_read(stream, asio::buffer(propertyBuffer), asio::deferred); diff --git a/src/IMessage.cpp b/src/IMessage.cpp index 191dea5..82a0833 100644 --- a/src/IMessage.cpp +++ b/src/IMessage.cpp @@ -3,6 +3,8 @@ #include #include +// So debug message can just reply +#include "DirtySockClient.hpp" #include "WireMessage.hpp" namespace ls { @@ -156,6 +158,9 @@ namespace ls { for(auto [key, value] : properties) base::LogInfo("{}: {}", key, value); + + // :( but it works to just replay the message. + co_await client->WriteMessage(std::make_shared(*this)); co_return; } }; @@ -174,7 +179,7 @@ namespace ls { else ret = std::make_shared(header); - if(ret->ParseFromInputBuffer(propertyDataBuffer)) + if(!ret->ParseFromInputBuffer(propertyDataBuffer)) return nullptr; return ret;