Scripts/Commands: Add .debug asan commands

Add ".debug asan memoryleak" and ".debug asan outofbounds" commands to trigger Address Sanitizer warnings at runtime (or other dynamic analysis tools)

(cherry picked from commit 71d15ea25b)
This commit is contained in:
jackpoz
2019-04-27 18:39:06 +02:00
committed by Shauren
parent dc2fed13c8
commit c73fd0e6e3
5 changed files with 46 additions and 1 deletions

View File

@@ -2151,6 +2151,7 @@ INSERT INTO `rbac_permissions` VALUES
(871,'Command: debug instancespawn'),
(872,'Command: server debug'),
(873,'Command: reload creature_movement_override'),
(874,'Command: debug asan'),
(881,'Command: reload vehicle_template'),
(882,'Command: reload spell_script_names');
/*!40000 ALTER TABLE `rbac_permissions` ENABLE KEYS */;
@@ -2383,6 +2384,7 @@ INSERT INTO `updates` VALUES
('2018_09_17_00_auth.sql','4DB671F0A4FA1A93AF28FB6426AF13DE72C7DA3D','ARCHIVED','2018-09-17 00:00:00',0),
('2018_12_09_00_auth_2017_01_06_00_auth.sql','6CCFE6A9774EC733C9863D36A0F15F3534189BBD','ARCHIVED','2017-01-06 00:00:00',0),
('2018_12_09_01_auth.sql','576C2A11BE671D8420FA3EB705E594E381ECCC56','ARCHIVED','2018-12-09 14:49:17',0),
('2019_04_27_00_auth.sql','84B1EB9CC9B09BAF55E6295D202EC57D99B1B60E','ARCHIVED','2019-04-27 18:07:18',0),
('2019_06_08_00_auth.sql','EA5A78F5A26C17BC790481EA9B3772D3A6912459','ARCHIVED','2019-05-20 17:21:20',0),
('2019_06_08_01_auth.sql','8165B1B787E3ECF0C8C0AD2D641513270977ABB4','ARCHIVED','2019-06-04 16:51:31',0),
('2019_06_08_02_auth.sql','B39DCBD902290700A81C9D028F54B58601C19A99','ARCHIVED','2019-06-05 16:26:31',0),

View File

@@ -0,0 +1,3 @@
--
DELETE FROM `rbac_permissions` WHERE `id`= 874;
INSERT INTO `rbac_permissions` (`id`,`name`) VALUES (874, 'Command: debug asan');

View File

@@ -0,0 +1,18 @@
--
DELETE FROM `command` WHERE `name`='debug asan';
INSERT INTO `command` (`name`,`permission`,`help`) VALUES
('debug asan',874,'Syntax: .debug asan $subcommand
Type .debug asan to see the list of possible subcommands or .help debug asan $subcommand to see info on subcommands.
Use only when testing dynamic analysis tools.');
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.');
DELETE FROM `command` WHERE `name`='debug asan memoryleak';
INSERT INTO `command` (`name`,`permission`,`help`) VALUES
('debug asan memoryleak',874,'Syntax: .debug asan memoryleak
Triggers a memory leak.
Use only when testing dynamic analysis tools.');

View File

@@ -779,7 +779,7 @@ enum RBACPermissions
RBAC_PERM_COMMAND_DEBUG_INSTANCESPAWN = 871,
RBAC_PERM_COMMAND_SERVER_DEBUG = 872,
RBAC_PERM_COMMAND_RELOAD_CREATURE_MOVEMENT_OVERRIDE = 873,
// = 874, // DEPRECATED: DON'T REUSE
RBAC_PERM_COMMAND_DEBUG_ASAN = 874,
RBAC_PERM_COMMAND_LOOKUP_MAP_ID = 875,
RBAC_PERM_COMMAND_LOOKUP_ITEM_ID = 876,
RBAC_PERM_COMMAND_LOOKUP_QUEST_ID = 877,

View File

@@ -84,6 +84,11 @@ public:
{ "spellfail", rbac::RBAC_PERM_COMMAND_DEBUG_SEND_SPELLFAIL, false, &HandleDebugSendSpellFailCommand, "" },
{ "playerchoice", rbac::RBAC_PERM_COMMAND_DEBUG_SEND_PLAYER_CHOICE, false, &HandleDebugSendPlayerChoiceCommand, "" },
};
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 =
{
{ "threat", rbac::RBAC_PERM_COMMAND_DEBUG_THREAT, false, &HandleDebugThreatListCommand, "" },
@@ -116,6 +121,7 @@ public:
{ "worldstate" , rbac::RBAC_PERM_COMMAND_DEBUG, false, &HandleDebugWorldStateCommand, "" },
{ "wsexpression" , rbac::RBAC_PERM_COMMAND_DEBUG, false, &HandleDebugWSExpressionCommand, "" },
{ "dummy", rbac::RBAC_PERM_COMMAND_DEBUG_DUMMY, false, &HandleDebugDummyCommand, "" },
{ "asan", rbac::RBAC_PERM_COMMAND_DEBUG_ASAN, true, nullptr, "", debugAsanCommandTable },
};
static std::vector<ChatCommand> commandTable =
{
@@ -1699,6 +1705,22 @@ public:
return true;
};
static bool HandleDebugOutOfBounds(ChatHandler* handler, CommandArgs* /*args*/)
{
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]);
return true;
}
static bool HandleDebugMemoryLeak(ChatHandler* handler, CommandArgs* /*args*/)
{
uint8* leak = new uint8();
handler->PSendSysMessage("Leaked 1 uint8 object at address %p", leak);
return true;
}
static bool HandleDebugDummyCommand(ChatHandler* handler, CommandArgs* /*args*/)
{
handler->SendSysMessage("This command does nothing right now. Edit your local core (cs_debug.cpp) to make it do whatever you need for testing.");