From f3fbf6beb8b767e2e45591a7daa605c413e2832b Mon Sep 17 00:00:00 2001 From: adf88 Date: Sun, 10 Sep 2017 14:02:13 +0000 Subject: (svn r27913) -Fix: 'unban' console command was not handling IPv6 adresses properly --- src/console_cmds.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/console_cmds.cpp') diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 9cfc8e8f9..d9706f7bf 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -562,20 +562,25 @@ DEF_CONSOLE_CMD(ConUnBan) if (argc != 2) return false; - uint index = (strchr(argv[1], '.') == NULL) ? atoi(argv[1]) : 0; - index--; - uint i = 0; + /* Try by IP. */ + uint index; + for (index = 0; index < _network_ban_list.Length(); index++) { + if (strcmp(_network_ban_list[index], argv[1]) == 0) break; + } - for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++, i++) { - if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) { - free(_network_ban_list[i]); - _network_ban_list.Erase(iter); - IConsolePrint(CC_DEFAULT, "IP unbanned."); - return true; - } + /* Try by index. */ + if (index >= _network_ban_list.Length()) { + index = atoi(argv[1]) - 1U; // let it wrap + } + + if (index < _network_ban_list.Length()) { + free(_network_ban_list[index]); + _network_ban_list.Erase(_network_ban_list.Get(index)); + IConsolePrint(CC_DEFAULT, "IP unbanned."); + } else { + IConsolePrint(CC_DEFAULT, "IP not in ban-list."); } - IConsolePrint(CC_DEFAULT, "IP not in ban-list."); return true; } -- cgit v1.2.3-54-g00ecf