Deny empty username early in the protocol
authorest31 <MTest31@outlook.com>
Fri, 22 May 2015 18:22:55 +0000 (20:22 +0200)
committerest31 <MTest31@outlook.com>
Fri, 22 May 2015 18:24:39 +0000 (20:24 +0200)
Thanks to @UltimateNate for pointing this out :)

src/network/serverpackethandler.cpp

index f658e106fa7b8d13757e6fce4fe3f5bc88c53bc2..4633aba8627e9c02448dcef316c33da5672b1ada 100644 (file)
@@ -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;
        }