From 5332fff5403f9c02d378c1c74264225444e61771 Mon Sep 17 00:00:00 2001 From: SwitchKaze Date: Mon, 20 Jul 2020 12:06:57 -0500 Subject: [PATCH] Deny standard color accessibility changes --- src/dehacked.c | 8 +++++--- src/lua_infolib.c | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 2e98a854c..cf891f438 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -808,9 +808,11 @@ static void readskincolor(MYFILE *f, INT32 num) { size_t namesize = sizeof(skincolors[num].name); char truncword[namesize]; + UINT16 dupecheck; deh_strlcpy(truncword, word2, namesize, va("Skincolor %d: name", num)); // truncate here to check for dupes - if (truncword[0] != '\0' && (!stricmp(truncword, skincolors[SKINCOLOR_NONE].name) || R_GetColorByName(truncword))) + dupecheck = R_GetColorByName(truncword); + if (truncword[0] != '\0' && (!stricmp(truncword, skincolors[SKINCOLOR_NONE].name) || dupecheck && dupecheck != num)) { size_t lastchar = strlen(truncword); char oldword[lastchar+1]; @@ -4726,11 +4728,11 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) { if (i == 0 && word2[0] != '0') // If word2 isn't a number i = get_skincolor(word2); // find a skincolor by name - if (i < numskincolors && i >= (INT32)SKINCOLOR_FIRSTFREESLOT) + if (i && i < numskincolors) readskincolor(f, i); else { - deh_warning("Skincolor %d out of range (%d - %d)", i, SKINCOLOR_FIRSTFREESLOT, numskincolors-1); + deh_warning("Skincolor %d out of range (1 - %d)", i, numskincolors-1); ignorelines(f); } } diff --git a/src/lua_infolib.c b/src/lua_infolib.c index a7fee8b03..830d97625 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -1569,8 +1569,13 @@ static int lib_setSkinColor(lua_State *L) info->invshade = (UINT8)luaL_checkinteger(L, 3)%COLORRAMPSIZE; else if (i == 5 || (str && fastcmp(str,"chatcolor"))) info->chatcolor = (UINT16)luaL_checkinteger(L, 3); - else if (i == 6 || (str && fastcmp(str,"accessible"))) - info->accessible = lua_toboolean(L, 3); + else if (i == 6 || (str && fastcmp(str,"accessible"))) { + boolean v = lua_toboolean(L, 3); + if (cnum < FIRSTSUPERCOLOR && v != skincolors[cnum].accessible) + return luaL_error(L, "skincolors[] index %d is a standard color; accessibility changes are prohibited.", cnum); + else + info->accessible = v; + } lua_pop(L, 1); } return 0; @@ -1655,9 +1660,13 @@ static int skincolor_set(lua_State *L) info->invshade = (UINT8)luaL_checkinteger(L, 3)%COLORRAMPSIZE; else if (fastcmp(field,"chatcolor")) info->chatcolor = (UINT16)luaL_checkinteger(L, 3); - else if (fastcmp(field,"accessible")) - info->accessible = lua_toboolean(L, 3); - else + else if (fastcmp(field,"accessible")) { + boolean v = lua_toboolean(L, 3); + if (cnum < FIRSTSUPERCOLOR && v != skincolors[cnum].accessible) + return luaL_error(L, "skincolors[] index %d is a standard color; accessibility changes are prohibited.", cnum); + else + info->accessible = v; + } else CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; returning nil.\n"), "skincolor_t", field); return 1; }