add parameter validation to checkcolor and f_font_group (#1145)

This commit is contained in:
Takase 2022-10-10 23:44:19 +08:00 committed by GitHub
parent 3409929a0c
commit 34c4ac3cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -137,7 +137,20 @@ static int f_font_copy(lua_State *L) {
}
static int f_font_group(lua_State* L) {
int table_size;
luaL_checktype(L, 1, LUA_TTABLE);
table_size = lua_rawlen(L, 1);
if (table_size >= FONT_FALLBACK_MAX)
return luaL_error(L, "failed to create font group: table size too large");
// we also need to ensure that there are no fontgroups inside it
for (int i = 1; i <= table_size; i++) {
if (lua_rawgeti(L, 1, i) != LUA_TUSERDATA)
return luaL_typeerror(L, -1, API_TYPE_FONT "(userdata)");
lua_pop(L, 1);
}
luaL_setmetatable(L, API_TYPE_FONT);
return 1;
}
@ -204,6 +217,7 @@ static RenColor checkcolor(lua_State *L, int idx, int def) {
if (lua_isnoneornil(L, idx)) {
return (RenColor) { def, def, def, 255 };
}
luaL_checktype(L, idx, LUA_TTABLE);
lua_rawgeti(L, idx, 1);
lua_rawgeti(L, idx, 2);
lua_rawgeti(L, idx, 3);