From 487917482fa506441100065a01f87fef5778f640 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 10 Nov 2022 18:13:20 +0100 Subject: [PATCH] fix out-of-range crash in SendFile when the UnsafeName does not contain a `/`, the server would simply crash, as an invalid substr() index was given, which triggered a std::out_of_range. --- src/TNetwork.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index b0615a7..5dfc3ef 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -650,7 +650,14 @@ void TNetwork::Parse(TClient& c, const std::vector& Packet) { } void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) { - beammp_info(c.GetName() + " requesting : " + UnsafeName.substr(UnsafeName.find_last_of('/'))); + 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"))) {