From 93b7fabac8e250b89227d1d183081326da942ade Mon Sep 17 00:00:00 2001 From: Alexander Baldeck Date: Fri, 26 Nov 2004 16:39:21 +0000 Subject: fix for tmw crash in login() due to too long username in tmw.ini (>25chars) (kth5) --- src/gui/login.cpp | 5 ++++- src/main.cpp | 4 ++-- src/main.h | 10 ++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 39a41d27..0fe00db0 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -43,7 +43,10 @@ DIALOG login_dialog[] = { if(get_config_int("login", "remember", 0)!=0) { login_dialog[7].flags = D_SELECTED; - if(get_config_string("login", "username", 0))strcpy(username, get_config_string("login", "username", 0)); + if(get_config_string("login", "username", 0)) { + strncpy(username, get_config_string("login", "username", 0), LEN_USERNAME); + username[LEN_USERNAME] = '\0'; + } else strcpy(username, "player\0"); } centre_dialog(login_dialog); diff --git a/src/main.cpp b/src/main.cpp index b9c501d3..87e1eb9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,8 +81,8 @@ PLAYER_INFO *char_info = new PLAYER_INFO; BITMAP *playerset, *hairset; DATAFILE *graphic, *emotions, *weaponset; -char username[25]; -char password[25]; +char username[LEN_USERNAME]; +char password[LEN_PASSWORD]; int map_address, char_ID; short map_port; char map_name[16]; diff --git a/src/main.h b/src/main.h index 951d6da9..b2eda9c0 100644 --- a/src/main.h +++ b/src/main.h @@ -59,6 +59,16 @@ #define CHAR_DEL 5 #define GAME 6 +/* length definitions for several char[]s in order + * to be able to use strncpy instead of strcpy for + * security and stability reasons + * + * best regards - kth5 */ +#define LEN_USERNAME 25 +#define LEN_PASSWORD 25 + + + typedef struct { int address; short port; -- cgit v1.2.3-70-g09d2