gopher-lua icon indicating copy to clipboard operation
gopher-lua copied to clipboard

RawSet accepts nil keys

Open frioux opened this issue 4 years ago • 0 comments

  • [x] GopherLua is a Lua5.1 implementation. You should be familiar with Lua programming language. Have you read Lua 5.1 reference manual carefully?
  • [x] GopherLua is a Lua5.1 implementation. In Lua, to keep it simple, it is more important to remove functionalities rather than to add functionalities unlike other languages . If you are going to introduce some new cool functionalities into the GopherLua code base and the functionalities can be implemented by existing APIs, It should be implemented as a library.

Please answer the following before submitting your issue:

  1. What version of GopherLua are you using? : ee81675732da
  2. What version of Go are you using? : 1.16
  3. What operating system and processor architecture are you using? : ubuntu
  4. What did you do? : (accidentally) called lua.LTable.RawSet with a nil key
  5. What did you expect to see? : a panic
  6. What did you see instead? : a silently corrupted table

The C API doesn't work this way; try this:

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdio.h>

int
main(void)
{
    lua_State *L;
    L = luaL_newstate();

    luaL_openlibs(L);
    lua_getglobal(L, "_G");
    lua_pushnil(L);
    lua_pushliteral(L, "whatever");
    lua_rawset(L, -3);

    lua_close(L);

    return 0;
}

h/t to @hoelzro for helping me verify this

frioux avatar May 05 '21 19:05 frioux