1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-29 16:31:18 +01:00

pkg/lua: detect if weak symbol has been overriden.

After removing the default definitions of lua module tables and table
lengths (see lua_builtin.h) the symbols have been left undefined, which
results in them getting an address of NULL and a crash if there are no
user symbols and the user attempts a "require".

This patch checks the address of the table length variable and fails the
module search function of the table is not set (i.e. it behaves as if the
table was empty.)
This commit is contained in:
Juan Carrano 2019-05-29 14:37:19 +02:00
parent fe07bff90c
commit 56eb7d9d92

View File

@ -42,12 +42,17 @@
/* ======================== 'searchers' functions =========================== */
/* A null address for table_len means the weak symbol was not overridden */
#define _SEARCH_BUILTINS(table, len, sname) \
((&(len) == NULL)? NULL : BINSEARCH_STR_P((table), (len), name, (sname), \
LUAR_MAX_MODULE_NAME))
static int _ll_searcher_builtin_lua(lua_State *L, const char *name)
{
const struct lua_riot_builtin_lua *lmodule =
BINSEARCH_STR_P(lua_riot_builtin_lua_table,
lua_riot_builtin_lua_table_len,
name, name, LUAR_MAX_MODULE_NAME);
_SEARCH_BUILTINS(lua_riot_builtin_lua_table,
lua_riot_builtin_lua_table_len,
name);
if (lmodule != NULL) {
int load_result = luaL_loadbuffer(L, (const char *)lmodule->code,
@ -90,9 +95,9 @@ static int searcher_builtin_lua(lua_State *L)
static int _ll_searcher_builtin_c(lua_State *L, const char *name)
{
const struct lua_riot_builtin_c *cmodule =
BINSEARCH_STR_P(lua_riot_builtin_c_table,
lua_riot_builtin_c_table_len,
name, name, LUAR_MAX_MODULE_NAME);
_SEARCH_BUILTINS(lua_riot_builtin_c_table,
lua_riot_builtin_c_table_len,
name);
if (cmodule != NULL) {
lua_pushcfunction(L, cmodule->luaopen);