Skip to content

Commit b8f6bd4

Browse files
committed
Prevent infinite loops if plugin state save calls SaveState
1 parent 0079c5d commit b8f6bd4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

plugins.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ CPlugin::CPlugin (CMUSHclientDoc * pDoc)
165165
m_bGlobal = false;
166166
m_iLoadOrder = 0;
167167
m_iScriptTimeTaken = 0;
168+
m_bSavingStateNow = false;
168169

169170
} // end of constructor
170171

@@ -784,9 +785,15 @@ bool bError = true;
784785
CPlugin * oldPlugin = m_pDoc->m_CurrentPlugin;
785786
m_pDoc->m_CurrentPlugin = this;
786787

788+
// prevent infinite loops
789+
m_bSavingStateNow = true;
790+
787791
CScriptCallInfo callinfo (ON_PLUGIN_SAVE_STATE, m_PluginCallbacks [ON_PLUGIN_SAVE_STATE]);
788792
ExecutePluginScript (callinfo);
789793

794+
// are not saving state now
795+
m_bSavingStateNow = false;
796+
790797
strFilename += m_pDoc->m_strWorldID; // world ID
791798
strFilename += "-";
792799
strFilename += m_strID; // plugin ID

plugins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class CPlugin :public CObject
103103
bool m_bGlobal; // true if plugin was loaded from global prefs
104104
long m_iLoadOrder; // sequence in which plugins are processed
105105
LONGLONG m_iScriptTimeTaken; // time taken to execute scripts
106+
bool m_bSavingStateNow; // to prevent infinite loops
106107

107108
// Lua note - for Lua the DISPID is a flag indicating whether or not
108109
// the routine exists. It is set to DISPID_UNKNOWN if the last call caused an error

scripting/methods/methods_plugins.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ long CMUSHclientDoc::SaveState()
500500
if (!m_CurrentPlugin)
501501
return eNotAPlugin;
502502

503+
// if we are already saving the state, don't do it again
504+
if (m_CurrentPlugin->m_bSavingStateNow)
505+
return ePluginCouldNotSaveState;
506+
507+
// save the state
503508
if (m_CurrentPlugin->SaveState (true))
504509
return ePluginCouldNotSaveState;
505510

0 commit comments

Comments
 (0)