From 268b79cb612668dcfee2b0c3b78870c42b4c5b37 Mon Sep 17 00:00:00 2001 From: dobrykafe Date: Mon, 26 Feb 2024 18:43:51 +0100 Subject: [PATCH] handle invalid filename for `save_replay` --- src/engine/client/client.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index c00621686..b38460754 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3466,9 +3466,6 @@ void CClient::SaveReplay(const int Length, const char *pFilename) } else { - // First we stop the recorder to slice correctly the demo after - DemoRecorder(RECORDER_REPLAYS)->Stop(IDemoRecorder::EStopMode::KEEP_FILE); - char aFilename[IO_MAX_PATH_LENGTH]; if(pFilename[0] == '\0') { @@ -3479,8 +3476,19 @@ void CClient::SaveReplay(const int Length, const char *pFilename) else { str_format(aFilename, sizeof(aFilename), "demos/replays/%s.demo", pFilename); + IOHANDLE Handle = m_pStorage->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); + if(!Handle) + { + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", "ERROR: invalid filename. Try a different one!"); + return; + } + io_close(Handle); + m_pStorage->RemoveFile(aFilename, IStorage::TYPE_SAVE); } + // Stop the recorder to correctly slice the demo after + DemoRecorder(RECORDER_REPLAYS)->Stop(IDemoRecorder::EStopMode::KEEP_FILE); + // Slice the demo to get only the last cl_replay_length seconds const char *pSrc = m_aDemoRecorder[RECORDER_REPLAYS].CurrentFilename(); const int EndTick = GameTick(g_Config.m_ClDummy);