From 4cd8e420a2e9f6fd2b32027ccd47f4c78aa09f65 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 22 May 2015 20:22:55 +0200 Subject: [PATCH] Deny empty username early in the protocol Thanks to @UltimateNate for pointing this out :) --- src/network/serverpackethandler.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index f658e106f..4633aba86 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -164,9 +164,11 @@ void Server::handleCommand_Init(NetworkPacket* pkt) */ const char* playername = playerName.c_str(); - if (playerName.size() > PLAYERNAME_SIZE) { - actionstream << "Server: Player with an too long name " - << "tried to connect from " << addr_s << std::endl; + size_t pns = playerName.size(); + if (pns == 0 || pns > PLAYERNAME_SIZE) { + actionstream << "Server: Player with " + << ((pns > PLAYERNAME_SIZE) ? "a too long" : "an empty") + << " name tried to connect from " << addr_s << std::endl; DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_NAME); return; }