Scripts/Commands: Revert e18f7aa, re-add .debug asan outofbounds, move bodies to #ifdef

This commit is contained in:
Treeston
2020-08-17 22:54:39 +02:00
parent 76f309b4e8
commit 0b13fc1926
2 changed files with 20 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
--
DELETE FROM `command` WHERE `name`='debug asan outofbounds';
INSERT INTO `command` (`name`,`permission`,`help`) VALUES
('debug asan outofbounds',874,'Syntax: .debug asan outofbounds
Triggers a stack out of bounds read.
Use only when testing dynamic analysis tools.');

View File

@@ -81,6 +81,7 @@ public:
static std::vector<ChatCommand> debugAsanCommandTable =
{
{ "memoryleak", rbac::RBAC_PERM_COMMAND_DEBUG_ASAN, true, &HandleDebugMemoryLeak, "" },
{ "outofbounds", rbac::RBAC_PERM_COMMAND_DEBUG_ASAN, true, &HandleDebugOutOfBounds, "" },
};
static std::vector<ChatCommand> debugCommandTable =
{
@@ -1704,10 +1705,23 @@ public:
return true;
}
static bool HandleDebugOutOfBounds(ChatHandler* handler, CommandArgs* /*args*/)
{
#ifdef ASAN
uint8 stack_array[10] = {};
int size = 10;
handler->PSendSysMessage("Triggered an array out of bounds read at address %p, value %u", stack_array + size, stack_array[size]);
#endif
return true;
}
static bool HandleDebugMemoryLeak(ChatHandler* handler)
{
#ifdef ASAN
uint8* leak = new uint8();
handler->PSendSysMessage("Leaked 1 uint8 object at address %p", leak);
#endif
return true;
}