Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sapier
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sapier/87e1332c54c130c24a7c to your computer and use it in GitHub Desktop.
Save sapier/87e1332c54c130c24a7c to your computer and use it in GitHub Desktop.
diff --git a/src/main.cpp b/src/main.cpp
index bb2ac5f..a44a2e6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -79,6 +79,7 @@
#include "httpfetch.h"
#include "guiEngine.h"
#include "mapsector.h"
+#include "player.h"
#include "database-sqlite3.h"
#ifdef USE_LEVELDB
@@ -1843,6 +1844,13 @@ int main(int argc, char *argv[])
break;
}
+ if (current_playername.length() > PLAYERNAME_SIZE-1) {
+ error_message = wgettext("Player name to long.");
+ playername = current_playername.substr(0,PLAYERNAME_SIZE-1);
+ g_settings->set("name", playername);
+ continue;
+ }
+
/*
Run game
*/
diff --git a/src/server.cpp b/src/server.cpp
index 920b9aa..0f1fdd4 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1450,12 +1450,15 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
*/
// Get player name
- char playername[PLAYERNAME_SIZE];
- for(u32 i=0; i<PLAYERNAME_SIZE-1; i++)
- {
- playername[i] = data[3+i];
+ if (strlen((char*) &data[3]) > (PLAYERNAME_SIZE - 1)) {
+ actionstream<<"Server: Player with name exceeding max player name length "
+ <<"tried to connect from "<<addr_s<<std::endl;
+ DenyAccess(peer_id, L"Name too long");
+ return;
}
- playername[PLAYERNAME_SIZE-1] = 0;
+
+ char playername[PLAYERNAME_SIZE];
+ strncpy(playername,(char*) &data[3], PLAYERNAME_SIZE);
if(playername[0]=='\0')
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment