Skip to content

Commit d7d8aa1

Browse files
sapiersapier
sapier
authored and
sapier
committedAug 22, 2014
Add player name length checks
1 parent 8e9d896 commit d7d8aa1

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed
 

‎src/main.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
7979
#include "httpfetch.h"
8080
#include "guiEngine.h"
8181
#include "mapsector.h"
82+
#include "player.h"
8283

8384
#include "database-sqlite3.h"
8485
#ifdef USE_LEVELDB
@@ -1843,6 +1844,13 @@ int main(int argc, char *argv[])
18431844
break;
18441845
}
18451846

1847+
if (current_playername.length() > PLAYERNAME_SIZE-1) {
1848+
error_message = wgettext("Player name to long.");
1849+
playername = current_playername.substr(0,PLAYERNAME_SIZE-1);
1850+
g_settings->set("name", playername);
1851+
continue;
1852+
}
1853+
18461854
/*
18471855
Run game
18481856
*/

‎src/server.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -1448,14 +1448,21 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
14481448
/*
14491449
Set up player
14501450
*/
1451-
1452-
// Get player name
14531451
char playername[PLAYERNAME_SIZE];
1454-
for(u32 i=0; i<PLAYERNAME_SIZE-1; i++)
1455-
{
1456-
playername[i] = data[3+i];
1452+
unsigned int playername_length = 0;
1453+
for (; playername_length < PLAYERNAME_SIZE; playername_length++ ) {
1454+
playername[playername_length] = data[3+playername_length];
1455+
if (data[3+playername_length] == 0)
1456+
break;
1457+
}
1458+
1459+
if (playername_length == PLAYERNAME_SIZE) {
1460+
actionstream<<"Server: Player with name exceeding max length "
1461+
<<"tried to connect from "<<addr_s<<std::endl;
1462+
DenyAccess(peer_id, L"Name to long");
1463+
return;
14571464
}
1458-
playername[PLAYERNAME_SIZE-1] = 0;
1465+
14591466

14601467
if(playername[0]=='\0')
14611468
{

0 commit comments

Comments
 (0)