Skip to content

Commit d9aa88e

Browse files
vrn-snkhvzak
andauthored
Fix crash when require is called from root VM stack (luau-lang#1788)
Copied from luau-lang#1785: > If require is called from the root interpreter stack (e.g. using C API) then lua_getinfo call will not succeed, leaving garbage in lua_Debug ar struct. > Accessing later ar.source as null-terminated string is unsafe and can cause a crash. > > This PR adds a check to ensure that lua_getinfo call is successful. Co-authored-by: Alex Orlenko <zxteam@protonmail.com>
1 parent c517432 commit d9aa88e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Require/Runtime/src/RequireImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ int lua_proxyrequire(lua_State* L)
170170
int lua_require(lua_State* L)
171171
{
172172
lua_Debug ar;
173-
lua_getinfo(L, 1, "s", &ar);
173+
if (!lua_getinfo(L, 1, "s", &ar))
174+
luaL_error(L, "require is not supported in this context");
174175
return lua_requireinternal(L, ar.source);
175176
}
176177

0 commit comments

Comments
 (0)