From 6c03d72c26a41d320ca59a67aecb036875c0d10d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 13 Jan 2024 13:22:52 +0900 Subject: [PATCH] [qw] Clean up player info processing It should be much harder for a malicious server to crash the client (there were a few holes in there still). Also, set the fallback (server didn't specify) top/bottom colors to be such that the default colors from the skin are used instead of white. --- include/QF/skin.h | 6 +++-- nq/source/cl_parse.c | 4 ++-- qw/source/cl_parse.c | 52 +++++++++++++++++--------------------------- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/include/QF/skin.h b/include/QF/skin.h index 75272a26a..4d65c8830 100644 --- a/include/QF/skin.h +++ b/include/QF/skin.h @@ -35,8 +35,10 @@ #define MAX_CACHED_SKINS 128 #define MAX_SKIN_LENGTH 32 -#define TOP_RANGE 16 // soldier uniform colors -#define BOTTOM_RANGE 96 +#define TOP_COLOR 1 // soldier uniform colors +#define BOTTOM_COLOR 6 +#define TOP_RANGE (TOP_COLOR * 16) +#define BOTTOM_RANGE (BOTTOM_COLOR * 16) #define RSSHOT_WIDTH 320 #define RSSHOT_HEIGHT 200 diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index c233d9207..f2b7cf54e 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -310,8 +310,8 @@ CL_ParseServerInfo (void) for (i = 0; i < cl.maxclients; i++) { cl.players[i].userinfo = Info_ParseString ("name\\", 0, 0); cl.players[i].name = Info_Key (cl.players[i].userinfo, "name"); - cl.players[i].topcolor = 0; - cl.players[i].bottomcolor = 0; + cl.players[i].topcolor = TOP_COLOR; + cl.players[i].bottomcolor = BOTTOM_COLOR; } Sbar_SetPlayers (cl.players, cl.maxclients); Sbar_SetTeamplay (teamplay);//FIXME updates? diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index aa7f36bb7..37a754536 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -996,42 +996,30 @@ CL_ParseClientdata (void) static void CL_ProcessUserInfo (int slot, player_info_t *player) { - char skin[MAX_SKIN_LENGTH] = { 0 }; - const char *s; - - s = Info_ValueForKey (player->userinfo, "skin"); - - if (strlen(s) < sizeof skin) { - QFS_StripExtension (s, skin); - if (!strequal (s, skin)) - Info_SetValueForKey (player->userinfo, "skin", skin, 1); - } else { - Info_SetValueForKey (player->userinfo, "skin", skin, 1); - } - while (!(player->name = Info_Key (player->userinfo, "name"))) { - if (player->userid) - Info_SetValueForKey (player->userinfo, "name", - va (0, "user-%i [exploit]", - player->userid), 1); - else - Info_SetValueForKey (player->userinfo, "name", "", 1); + const char *name = ""; + if (player->userid) { + name = va (0, "user-%i [exploit]", player->userid); + } + Info_SetValueForKey (player->userinfo, "name", name, 1); } - player->topcolor = atoi (Info_ValueForKey (player->userinfo, "topcolor")); - player->bottomcolor = - atoi (Info_ValueForKey (player->userinfo, "bottomcolor")); + const char *tc = Info_ValueForKey (player->userinfo, "topcolor"); + const char *bc = Info_ValueForKey (player->userinfo, "bottomcolor"); + player->topcolor = tc ? atoi (tc) : TOP_COLOR; + player->bottomcolor = bc ? atoi (bc) : BOTTOM_COLOR; - while (!(player->team = Info_Key (player->userinfo, "team"))) - Info_SetValueForKey (player->userinfo, "team", "", 1); - while (!(player->skinname = Info_Key (player->userinfo, "skin"))) - Info_SetValueForKey (player->userinfo, "skin", "", 1); - while (!(player->chat = Info_Key (player->userinfo, "chat"))) - Info_SetValueForKey (player->userinfo, "chat", "0", 1); + while (!(player->team = Info_Key (player->userinfo, "team"))) { + Info_SetValueForKey (player->userinfo, "team", "", 1); + } + while (!(player->skinname = Info_Key (player->userinfo, "skin"))) { + Info_SetValueForKey (player->userinfo, "skin", "", 1); + } + while (!(player->chat = Info_Key (player->userinfo, "chat"))) { + Info_SetValueForKey (player->userinfo, "chat", "0", 1); + } - if (Info_ValueForKey (player->userinfo, "*spectator")[0]) - player->spectator = true; - else - player->spectator = false; + const char *spec = Info_ValueForKey (player->userinfo, "*spectator"); + player->spectator = spec && *spec; mod_funcs->Skin_SetTranslation (slot + 1, player->topcolor, player->bottomcolor);