Fix out-of-bounds crash in PluginIterator_Next (#2445)

* Fix OOB dereference in PluginIterator methodmap (#1880)

This prevents the native from returning true when the iterator has already reached the end() of the list, which previously led to a crash when accessing the Plugin property.

* Add defense-in-depth safeguards to CMMPluginIterator

* Update PluginIterator.Next() @error documentation

Reflect the new NativeError thrown when calling Next() on an exhausted iterator.
This commit is contained in:
SCP-076
2026-04-25 17:11:28 +00:00
committed by GitHub
parent 7f2528d0fa
commit 94adc98ef5
2 changed files with 11 additions and 7 deletions
+10 -6
View File
@@ -151,6 +151,8 @@ public:
}
virtual IPlugin *GetPlugin() override
{
if (m_current == m_list.end())
return nullptr;
return *m_current;
}
virtual void NextPlugin() override
@@ -161,7 +163,8 @@ public:
return;
}
m_current++;
if (m_current != m_list.end())
m_current++;
}
virtual void Release() override
{
@@ -171,7 +174,7 @@ public:
public:
virtual void OnPluginDestroyed(IPlugin *plugin) override
{
if (*m_current == plugin)
if (m_current != m_list.end() && *m_current == plugin)
m_current = m_list.erase(m_current);
else
m_list.remove(static_cast<SMPlugin *>(plugin));
@@ -401,12 +404,13 @@ static cell_t PluginIterator_Next(IPluginContext *pContext, const cell_t *params
{
return pContext->ThrowNativeError("Could not read Handle %x (error %d)", hndl, err);
}
if(!pIter->MorePlugins())
return 0;
return pContext->ThrowNativeError("PluginIterator %x is exhausted.", hndl);
pIter->NextPlugin();
return 1;
return pIter->MorePlugins() ? 1 : 0;
}
static cell_t PluginIterator_Plugin_get(IPluginContext *pContext, const cell_t *params)
+1 -1
View File
@@ -262,7 +262,7 @@ methodmap PluginIterator < Handle
// Advances the iterator. Returns whether there are more plugins available in the iterator.
//
// @return True on more plugins, false otherwise.
// @error Invalid Handle.
// @error Invalid Handle, or called when the iterator is already exhausted.
public native bool Next();
// Returns the current plugin in the iterator.