aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjackpoz <giacomopoz@gmail.com>2019-04-27 18:39:06 +0200
committerShauren <shauren.trinity@gmail.com>2021-12-02 00:39:20 +0100
commitc73fd0e6e30f6dff0d2f721f549aed2c62e52c24 (patch)
tree68a716a330e96a1ded4b709257d226e349d99ba5
parentdc2fed13c8a98123ff20316428e41eada36c81e9 (diff)
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 71d15ea25be3e86646faaa3266617a0b8177972f)
-rw-r--r--sql/base/auth_database.sql2
-rw-r--r--sql/updates/auth/master/2019_04_27_00_auth.sql3
-rw-r--r--sql/updates/world/master/2021_12_01_04_world_2019_04_27_00_world.sql18
-rw-r--r--src/server/game/Accounts/RBAC.h2
-rw-r--r--src/server/scripts/Commands/cs_debug.cpp22
5 files changed, 46 insertions, 1 deletions
diff --git a/sql/base/auth_database.sql b/sql/base/auth_database.sql
index 7e6c288e045..585914883e0 100644
--- a/sql/base/auth_database.sql
+++ b/sql/base/auth_database.sql
@@ -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),
diff --git a/sql/updates/auth/master/2019_04_27_00_auth.sql b/sql/updates/auth/master/2019_04_27_00_auth.sql
new file mode 100644
index 00000000000..d8f01cc9db3
--- /dev/null
+++ b/sql/updates/auth/master/2019_04_27_00_auth.sql
@@ -0,0 +1,3 @@
+--
+DELETE FROM `rbac_permissions` WHERE `id`= 874;
+INSERT INTO `rbac_permissions` (`id`,`name`) VALUES (874, 'Command: debug asan');
diff --git a/sql/updates/world/master/2021_12_01_04_world_2019_04_27_00_world.sql b/sql/updates/world/master/2021_12_01_04_world_2019_04_27_00_world.sql
new file mode 100644
index 00000000000..87f7cacf4dd
--- /dev/null
+++ b/sql/updates/world/master/2021_12_01_04_world_2019_04_27_00_world.sql
@@ -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.');
diff --git a/src/server/game/Accounts/RBAC.h b/src/server/game/Accounts/RBAC.h
index b93d99a9144..b376624a235 100644
--- a/src/server/game/Accounts/RBAC.h
+++ b/src/server/game/Accounts/RBAC.h
@@ -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,
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp
index 83b70f51c92..ab1aec347ba 100644
--- a/src/server/scripts/Commands/cs_debug.cpp
+++ b/src/server/scripts/Commands/cs_debug.cpp
@@ -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.");