about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-12-07 08:50:28 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-07 08:50:28 -0800
commit46aa8c2cf8bdc6d45fb1bbf06b595f4590c5500c (patch)
treeba425650d97c0e0c62dd740575be06e756e3219c
parent0e8a160eeea072c09fadca8c38d9f45bd7dce63f (diff)
downloadteliva-46aa8c2cf8bdc6d45fb1bbf06b595f4590c5500c.tar.gz
slightly improve experience on Konrad Hinsen's bug
Steps to reproduce:
* Run teliva with some app.
* Press ctrl-e to edit the app.
* Select some function.
* Press ctrl-g and type in some Lua keyword like 'function' or 'while'
  (Since the first word in a function is often 'function', it becomes
  the default if you press ctrl-g immediately after entering the editor
  for a function.)
* Type nothing. Run the app.

Desired behavior: app continues to run. The definition for the keyword
is silently ignored (in future we may want to provide an error message)

Behavior before this commit: app silently exited with non-zero status,
and refused to restart thereafter until the .tlv file was manually
edited to delete the definition for the Lua keyword.

Behavior after this commit: app throws an error message like these:

  * For `function`:
    ```
    src/teliva: x.tlv:99: '(' expected near '='
    sorry, you'll need to edit the image directly. press any key to exit.
    ```

  * For `while`:
    ```
    src/teliva: x.tlv:99: unexpected symbol near 'while'
    sorry, you'll need to edit the image directly. press any key to exit.
    ```

You still need to edit the .tlv file manually, but the steps for
recovery are a bit more discoverable.

To fix this properly I also need to fix a looming security hole I've
been thinking about for some time. The long-term goal of Teliva is to
put the human running apps in control of what they do, by sandboxing
accesses to the file system, network and so on. However, even after we
build gates on all of Lua's standard libraries, we're still parsing .tlv
files as Lua, with all of its power available.

Solution: load .tlv files as some sort of JSON-like subset of Lua. Maybe
I should just use JSON, and rely on code that's already in Teliva, even
if I'm introducing a new notation in the process.
-rw-r--r--src/lua.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/lua.c b/src/lua.c
index 5874502..e846f72 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -334,7 +334,7 @@ static int handle_image (lua_State *L, char **argv, int n) {
   Image_name = argv[n];
   status = luaL_loadfile(L, Image_name);
   lua_insert(L, -(narg+1));
-  if (status != 0) return status;
+  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 */
   status = load_definitions(L);