From b548ba7b58c4f1c2f7e0f168762deb6c3eb0796f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 8 Sep 2015 19:47:22 -0700 Subject: [PATCH] Remove bad-console-read protection logic for Metamod:Source 1.7 and earlier. --- core/ConCmdManager.cpp | 12 ++--- core/ConCmdManager.h | 4 +- core/ConVarManager.cpp | 2 +- core/ConVarManager.h | 2 +- core/concmd_cleaner.cpp | 105 +++++++++++++++------------------------- core/concmd_cleaner.h | 2 +- core/smn_console.cpp | 2 +- 7 files changed, 50 insertions(+), 79 deletions(-) diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index 937114a5..2d194b14 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -73,7 +73,7 @@ void ConCmdManager::OnSourceModShutdown() rootmenu->RemoveRootConsoleCommand("cmds", this); } -void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) +void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) { /* Whoa, first get its information struct */ ConCmdInfo *pInfo; @@ -108,7 +108,7 @@ void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *na delete hook; } - RemoveConCmd(pInfo, name, is_read_safe, false); + RemoveConCmd(pInfo, name, false); } void ConCmdManager::OnPluginDestroyed(IPlugin *plugin) @@ -127,7 +127,7 @@ void ConCmdManager::OnPluginDestroyed(IPlugin *plugin) hook->admin->group->hooks.remove(hook); if (hook->info->hooks.empty()) - RemoveConCmd(hook->info, hook->info->pCmd->GetName(), true, true); + RemoveConCmd(hook->info, hook->info->pCmd->GetName(), true); iter = pList->erase(iter); delete hook; @@ -517,7 +517,7 @@ void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, Flag } } -void ConCmdManager::RemoveConCmd(ConCmdInfo *info, const char *name, bool is_read_safe, bool untrack) +void ConCmdManager::RemoveConCmd(ConCmdInfo *info, const char *name, bool untrack) { /* Remove from the trie */ m_Cmds.remove(name); @@ -540,10 +540,6 @@ void ConCmdManager::RemoveConCmd(ConCmdInfo *info, const char *name, bool is_rea } else { - // If it's not safe to read the pointer, we zap the SourceHook hook so it - // doesn't attempt to access the pointer's vtable. - if (!is_read_safe) - info->sh_hook->Zap(); if (untrack) UntrackConCommandBase(info->pCmd, this); } diff --git a/core/ConCmdManager.h b/core/ConCmdManager.h index f68991e2..c6edeb90 100644 --- a/core/ConCmdManager.h +++ b/core/ConCmdManager.h @@ -129,7 +129,7 @@ public: //IPluginsListener public: //IRootConsoleCommand void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override; public: //IConCommandTracker - void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); + void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) override; public: bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); bool AddAdminCommand(IPluginFunction *pFunction, @@ -148,7 +148,7 @@ private: ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags); void SetCommandClient(int client); void AddToCmdList(ConCmdInfo *info); - void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool is_read_safe, bool untrack); + void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool untrack); bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin); // Case insensitive diff --git a/core/ConVarManager.cpp b/core/ConVarManager.cpp index 11fcd00e..e3dfafac 100644 --- a/core/ConVarManager.cpp +++ b/core/ConVarManager.cpp @@ -167,7 +167,7 @@ bool convar_cache_lookup(const char *name, ConVarInfo **pVar) return convar_cache.retrieve(name, pVar); } -void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) +void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) { /* Only check convars that have not been created by SourceMod's core */ ConVarInfo *pInfo; diff --git a/core/ConVarManager.h b/core/ConVarManager.h index 414a0c8a..07dfdd35 100644 --- a/core/ConVarManager.h +++ b/core/ConVarManager.h @@ -103,7 +103,7 @@ public: // IPluginsListener public: //IRootConsoleCommand void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override; public: //IConCommandTracker - void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); + void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) override; public: //IClientListener void OnClientDisconnected(int client); public: diff --git a/core/concmd_cleaner.cpp b/core/concmd_cleaner.cpp index 009608b5..683cb68b 100644 --- a/core/concmd_cleaner.cpp +++ b/core/concmd_cleaner.cpp @@ -1,33 +1,29 @@ -/** - * vim: set ts=4 sw=4 tw=99 noet : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ +// vim: set ts=4 sw=4 tw=99 et: +// ============================================================================= +// SourceMod +// Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. +// ============================================================================= +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License, version 3.0, as published by the +// Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . +// +// As a special exception, AlliedModders LLC gives you permission to link the +// code of this program (as well as its derivative works) to "Half-Life 2," the +// "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software +// by the Valve Corporation. You must obey the GNU General Public License in +// all respects for all other code used. Additionally, AlliedModders LLC grants +// this exception to all derivative works. AlliedModders LLC defines further +// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), +// or . #include "sm_globals.h" #include @@ -104,41 +100,20 @@ public: listener = listener->next; } - if (pBase) - { - while (iter != tracked_bases.end()) - { - if ((*iter)->pBase == pBase) - { - pInfo = (*iter); - iter = tracked_bases.erase(iter); - pInfo->cls->OnUnlinkConCommandBase(pBase, pBase->GetName(), true); - delete pInfo; - } - else - { - iter++; - } - } - } - else - { - while (iter != tracked_bases.end()) - { - /* This is just god-awful! */ - if (FindCommandBase((*iter)->name) != (*iter)->pBase) - { - pInfo = (*iter); - iter = tracked_bases.erase(iter); - pInfo->cls->OnUnlinkConCommandBase(pBase, pInfo->name, false); - delete pInfo; - } - else - { - iter++; - } - } - } + while (iter != tracked_bases.end()) + { + if ((*iter)->pBase == pBase) + { + pInfo = (*iter); + iter = tracked_bases.erase(iter); + pInfo->cls->OnUnlinkConCommandBase(pBase, pBase->GetName()); + delete pInfo; + } + else + { + iter++; + } + } } void AddTarget(ConCommandBase *pBase, IConCommandTracker *cls) diff --git a/core/concmd_cleaner.h b/core/concmd_cleaner.h index 330a984e..87ba73a6 100644 --- a/core/concmd_cleaner.h +++ b/core/concmd_cleaner.h @@ -35,7 +35,7 @@ class IConCommandTracker { public: - virtual void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) = 0; + virtual void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) = 0; }; void TrackConCommandBase(ConCommandBase *pBase, IConCommandTracker *me); diff --git a/core/smn_console.cpp b/core/smn_console.cpp index 4ebd9123..ee59af55 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -131,7 +131,7 @@ public: class CommandFlagsHelper : public IConCommandTracker { public: - void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) + void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name) override { m_CmdFlags.remove(name); }