From c0f634005d8a0712c819875582018b31d52e43e2 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Thu, 28 Apr 2016 15:45:20 +0200 Subject: [PATCH] Check IDemoRecorder pointer before use If the pointer to the IDemoRecorder instance fails to be found after an update, don't try to use it blindly, but check if it's not null before.. --- hltvserverwrapper.cpp | 2 +- natives.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/hltvserverwrapper.cpp b/hltvserverwrapper.cpp index 4f3e7fc..c7c4af9 100644 --- a/hltvserverwrapper.cpp +++ b/hltvserverwrapper.cpp @@ -376,7 +376,7 @@ HLTVServerWrapper *HLTVServerWrapperManager::GetWrapper(IDemoRecorder *demorecor for (unsigned int i = 0; i < m_HLTVServers.length(); i++) { HLTVServerWrapper *wrapper = m_HLTVServers[i]; - if (wrapper->GetDemoRecorder() == demorecorder) + if (wrapper->GetDemoRecorder() != nullptr && wrapper->GetDemoRecorder() == demorecorder) return wrapper; } return nullptr; diff --git a/natives.cpp b/natives.cpp index 140d759..bc943c0 100644 --- a/natives.cpp +++ b/natives.cpp @@ -446,6 +446,8 @@ static cell_t Native_ForceChaseCameraShot(IPluginContext *pContext, const cell_t // native bool:SourceTV_IsRecording(); static cell_t Native_IsRecording(IPluginContext *pContext, const cell_t *params) { + if (!hltvserver || !hltvserver->GetDemoRecorder()) + return 0; return hltvserver->GetDemoRecorder()->IsRecording(); } @@ -468,6 +470,10 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para // Only SourceTV Master can record demos instantly if (!hltvserver->GetHLTVServer()->IsMasterProxy()) return 0; + + // Failed to find the IDemoRecorder instance + if (!hltvserver->GetDemoRecorder()) + return 0; // already recording if (hltvserver->GetDemoRecorder()->IsRecording()) @@ -514,6 +520,14 @@ static cell_t Native_StartRecording(IPluginContext *pContext, const cell_t *para // native bool:SourceTV_StopRecording(); static cell_t Native_StopRecording(IPluginContext *pContext, const cell_t *params) { + if (hltvserver == nullptr) + return 0; + + // Failed to find the IDemoRecorder instance + if (!hltvserver->GetDemoRecorder()) + return 0; + + // Not recording if (!hltvserver->GetDemoRecorder()->IsRecording()) return 0; @@ -530,6 +544,14 @@ static cell_t Native_StopRecording(IPluginContext *pContext, const cell_t *param // native bool:SourceTV_GetDemoFileName(String:sFilename[], maxlen); static cell_t Native_GetDemoFileName(IPluginContext *pContext, const cell_t *params) { + if (hltvserver == nullptr) + return 0; + + // Failed to find the IDemoRecorder instance + if (!hltvserver->GetDemoRecorder()) + return 0; + + // Not recording if (!hltvserver->GetDemoRecorder()->IsRecording()) return 0; @@ -549,6 +571,13 @@ static cell_t Native_GetDemoFileName(IPluginContext *pContext, const cell_t *par // native SourceTV_GetRecordingTick(); static cell_t Native_GetRecordingTick(IPluginContext *pContext, const cell_t *params) { + if (hltvserver == nullptr) + return -1; + + // Failed to find the IDemoRecorder instance + if (!hltvserver->GetDemoRecorder()) + return -1; + if (!hltvserver->GetDemoRecorder()->IsRecording()) return -1;