diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-12-11 00:30:42 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-12-11 00:43:26 -0800 |
commit | 0b0a58da066ba1da2d74348af66e85a7f7a95bbf (patch) | |
tree | 81c4b7bb3b7dca41d1b83118c7457f0f780be18c /src/lua.c | |
parent | 469ad4e5469b5cda4c61d39cc042852467691a82 (diff) | |
download | teliva-0b0a58da066ba1da2d74348af66e85a7f7a95bbf.tar.gz |
snapshot: start reading a new format
I really wanted to avoid getting into defining or parsing new file formats. However, using the entire power of Lua is not ideal, as described earlier in Konrad Hinsen's bug. In addition to everything else, it's a vector for arbitrary code execution when someone loads an untrusted image. I could use JSON, but it requires ugly string escaping. Seems cleaner to just use YAML. But YAML is complex and needs its own dependencies. If I'm going to do my own, might as well make the multi-line string format really clear. I can't yet write the new format.
Diffstat (limited to 'src/lua.c')
-rw-r--r-- | src/lua.c | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/src/lua.c b/src/lua.c index c245d24..eb16b51 100644 --- a/src/lua.c +++ b/src/lua.c @@ -168,25 +168,6 @@ static int docall (lua_State *L, int narg, int clear) { } -/* pushes commandline args to the stack, then an array of all commandline args */ -static int getargs (lua_State *L, char **argv, int n) { - int narg; - int i; - int argc = 0; - while (argv[argc]) argc++; /* count total number of arguments */ - narg = argc - (n + 1); /* number of arguments to the script */ - luaL_checkstack(L, narg + 3, "too many arguments to script"); - for (i=n+1; i < argc; i++) - lua_pushstring(L, argv[i]); - lua_createtable(L, narg, n + 1); - for (i=0; i < argc; i++) { - lua_pushstring(L, argv[i]); - lua_rawseti(L, -2, i - n); - } - return narg; -} - - static int dofile (lua_State *L, const char *name) { int status = luaL_loadfile(L, name) || docall(L, 0, 1); return report_in_developer_mode(L, status); @@ -326,17 +307,13 @@ int load_definitions(lua_State *L) { char *Image_name = NULL; +void load_tlv (lua_State *L, char *filename); static int handle_image (lua_State *L, char **argv, int n) { int status; - int narg = getargs(L, argv, n); /* collect arguments */ - lua_setglobal(L, "arg"); + /* TODO: pass args in */ /* parse and load file contents (teliva_program array) */ Image_name = argv[n]; - status = luaL_loadfile(L, Image_name); - lua_insert(L, -(narg+1)); - if (status != 0) return report(L, status); /* can't recover within teliva */ - status = docall(L, narg, 0); - if (status != 0) return report(L, status); /* can't recover within teliva */ + load_tlv(L, Image_name); status = load_definitions(L); if (status != 0) return 0; /* call main() */ |