From 3fcf23977b95d4a4bead8dbc2360a92f44808681 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 10 Nov 2022 18:41:22 +0100 Subject: [PATCH] fix fix for out-of-bounds crash, add disconnect messages to some failure conditions --- src/TNetwork.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 5dfc3ef..3b4d9df 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -652,16 +652,10 @@ void TNetwork::Parse(TClient& c, const std::vector& Packet) { void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) { beammp_infof("{} ({}) requesting : '{}'", c.GetName(), c.GetID(), UnsafeName); - if (!fs::exists(UnsafeName)) { - if (!TCPSend(c, StringToVector("CO"))) { - // TODO: handle - } - beammp_warn("File '" + UnsafeName + "' does not exist!"); - } - if (!fs::path(UnsafeName).has_filename()) { if (!TCPSend(c, StringToVector("CO"))) { - // TODO: handle + c.Disconnect("TCP send failed in SendFile, when trying to cancel file transfer because the requested file doesn't contain a valid filename"); + return; } beammp_warn("File " + UnsafeName + " is not a file!"); return; @@ -671,14 +665,15 @@ void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) { if (!std::filesystem::exists(FileName)) { if (!TCPSend(c, StringToVector("CO"))) { - // TODO: handle + c.Disconnect("TCP send failed in SendFile, when trying to cancel file transfer because the requested file doesn't exist or couldn't be accessed"); } beammp_warn("File " + UnsafeName + " could not be accessed!"); return; } if (!TCPSend(c, StringToVector("AG"))) { - // TODO: handle + c.Disconnect("TCP send failed in SendFile, when trying to send "); + return; } /// Wait for connections