Fix possible crashes in the Lua API when accessing invalid fields

https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2128\?commit_id\=6414e9db79771494f87662f902999a028aa385cd
This commit is contained in:
NepDisk 2024-08-01 02:54:12 -04:00
parent 091f781b49
commit eb93c8df5b
2 changed files with 9 additions and 5 deletions

View file

@ -543,7 +543,7 @@ static int cvar_get(lua_State *L)
else if(fastcmp(field,"changed"))
lua_pushboolean(L, cvar->changed);
else if (devparm)
return luaL_error(L, LUA_QL("consvar_t") " has no field named " LUA_QS, field);
return luaL_error(L, LUA_QL("consvar_t") " has no field named " LUA_QS ".", lua_tostring(L, 2));
else
return 0;
return 1;

View file

@ -646,8 +646,9 @@ static int sector_set(lua_State *L)
case sector_ffloors: // ffloors
case sector_fslope: // f_slope
case sector_cslope: // c_slope
return luaL_error(L, "sector_t has no field named " LUA_QS ".", lua_tostring(L, 2));
default:
return luaL_error(L, "sector_t field " LUA_QS " cannot be set.", sector_opt[field]);
return luaL_error(L, "sector_t has no field named " LUA_QS ".", lua_tostring(L, 2));
case sector_floorheight: { // floorheight
boolean flag;
mobj_t *ptmthing = tmthing;
@ -1022,8 +1023,9 @@ static int side_set(lua_State *L)
case side_sector:
case side_special:
case side_text:
default:
return luaL_error(L, "side_t field " LUA_QS " cannot be set.", side_opt[field]);
default:
return luaL_error(L, "side_t has no field named " LUA_QS ".", lua_tostring(L, 2));
case side_textureoffset:
side->textureoffset = luaL_checkfixed(L, 3);
break;
@ -1839,8 +1841,9 @@ static int ffloor_set(lua_State *L)
case ffloor_target: // target
case ffloor_next: // next
case ffloor_prev: // prev
default:
return luaL_error(L, "ffloor_t field " LUA_QS " cannot be set.", ffloor_opt[field]);
default:
return luaL_error(L, "ffloor_t has no field named " LUA_QS ".", lua_tostring(L, 2));
case ffloor_topheight: { // topheight
boolean flag;
fixed_t lastpos = *ffloor->topheight;
@ -1964,8 +1967,9 @@ static int slope_set(lua_State *L)
case slope_d: // d
case slope_flags: // flags
case slope_normal: // normal
default:
return luaL_error(L, "pslope_t field " LUA_QS " cannot be set.", slope_opt[field]);
default:
return luaL_error(L, "pslope_t has no field named " LUA_QS ".", lua_tostring(L, 2));
case slope_o: { // o
luaL_checktype(L, 3, LUA_TTABLE);