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.
This commit is contained in:
Lion Kortlepel
2022-11-10 18:13:20 +01:00
parent 2ca39a7368
commit 487917482f

View File

@@ -650,7 +650,14 @@ void TNetwork::Parse(TClient& c, const std::vector<uint8_t>& 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"))) {