aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-06-14 16:48:48 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-06-14 16:48:48 +0200
commite3f3288597dc62c9c26d89f92e396bc3abf4b408 (patch)
tree250beb191624642ffbecbcc8848c4c7b575420e3 /src
parent4d364d3e77667b70bf3261da004f4990ef0c3ada (diff)
downloadlanes-e3f3288597dc62c9c26d89f92e396bc3abf4b408.tar.gz
lanes-e3f3288597dc62c9c26d89f92e396bc3abf4b408.tar.bz2
lanes-e3f3288597dc62c9c26d89f92e396bc3abf4b408.zip
Fix error handling when indexing a lane with unexpected data
Diffstat (limited to 'src')
-rw-r--r--src/lane.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/lane.cpp b/src/lane.cpp
index 17c4126..a998e9c 100644
--- a/src/lane.cpp
+++ b/src/lane.cpp
@@ -352,10 +352,20 @@ static LUAG_FUNC(thread_index)
352 352
353 default: // unknown key 353 default: // unknown key
354 lua_getmetatable(L_, kSelf); // L_: mt 354 lua_getmetatable(L_, kSelf); // L_: mt
355 std::ignore = luaG_getfield(L_, -1, "cached_error"); // L_: mt error 355 kCachedError.pushKey(L_); // L_: mt kCachedError
356 luaG_pushstring(L_, "Unknown key: "); // L_: mt error "Unknown key: " 356 lua_rawget(L_, -2); // L_: mt error()
357 lua_pushvalue(L_, kKey); // L_: mt error "Unknown key: " k 357 if (luaG_type(L_, -1) != LuaType::FUNCTION) {
358 lua_concat(L_, 2); // L_: mt error "Unknown key: <k>" 358 raise_luaL_error(L_, "INTERNAL ERROR: cached error() is a %s, not a function", luaG_typename(L_, -1).data());
359 }
360 luaG_pushstring(L_, "Unknown key: "); // L_: mt error() "Unknown key: "
361 kCachedTostring.pushKey(L_); // L_: mt error() "Unknown key: " kCachedTostring
362 lua_rawget(L_, -4); // L_: mt error() "Unknown key: " tostring()
363 if (luaG_type(L_, -1) != LuaType::FUNCTION) {
364 raise_luaL_error(L_, "INTERNAL ERROR: cached tostring() is a %s, not a function", luaG_typename(L_, -1).data());
365 }
366 lua_pushvalue(L_, kKey); // L_: mt error() "Unknown key: " tostring() k
367 lua_call(L_, 1, 1); // L_: mt error() "Unknown key: " "k"
368 lua_concat(L_, 2); // L_: mt error() "Unknown key: <k>"
359 lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt 369 lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt
360 raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->debugName.data(), luaG_typename(L_, kKey).data()); 370 raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->debugName.data(), luaG_typename(L_, kKey).data());
361 } 371 }
@@ -965,7 +975,7 @@ namespace {
965 } // namespace local 975 } // namespace local
966} // namespace 976} // namespace
967 977
968 // contains keys: { __gc, __index, cached_error, cached_tostring, cancel, join, get_debug_threadname } 978 // contains keys: { __close, __gc, __index, kCachedError, kCachedTostring, cancel, get_debug_threadname, join }
969void Lane::PushMetatable(lua_State* L_) 979void Lane::PushMetatable(lua_State* L_)
970{ 980{
971 STACK_CHECK_START_REL(L_, 0); 981 STACK_CHECK_START_REL(L_, 0);