aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-07-22 13:48:43 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-07-22 13:48:43 -0300
commit439e45a2f69549b674d6a6e2023e8debfa00a2b8 (patch)
tree416db940cc3e4826119fda14d47f579b60cfb99b /lauxlib.c
parent62fb93442753cbfb828335cd172e71471dffd536 (diff)
downloadlua-439e45a2f69549b674d6a6e2023e8debfa00a2b8.tar.gz
lua-439e45a2f69549b674d6a6e2023e8debfa00a2b8.tar.bz2
lua-439e45a2f69549b674d6a6e2023e8debfa00a2b8.zip
Bug: luaL_tolstring may get confused with negative index
When object has a '__name' metafield, 'luaL_tolstring' used the received index after pushing a string on the stack.
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 94835ef9..8ed1da11 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -881,6 +881,7 @@ LUALIB_API lua_Integer luaL_len (lua_State *L, int idx) {
881 881
882 882
883LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { 883LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
884 idx = lua_absindex(L,idx);
884 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */ 885 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
885 if (!lua_isstring(L, -1)) 886 if (!lua_isstring(L, -1))
886 luaL_error(L, "'__tostring' must return a string"); 887 luaL_error(L, "'__tostring' must return a string");