Skip to content

Commit

Permalink
LRequest: destruct cgroup_xattr with the global Lua state
Browse files Browse the repository at this point in the history
    
When the current Lua thread is gone already, it must not be used to
destruct the `cgroup_xattr` field.
  • Loading branch information
MaxKellermann committed Nov 24, 2023
1 parent 42fafd8 commit aa2da29
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cm4all-passage (0.16) unstable; urgency=low

*
* fix use-after-free crash bug

--

Expand Down
3 changes: 2 additions & 1 deletion src/Connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ try {

handler->Push(L);

NewLuaRequest(L, std::move(request), peer_cred);
NewLuaRequest(L, instance.GetLuaState(),
std::move(request), peer_cred);
if (lua_pcall(L, 1, 1, 0))
throw Lua::PopError(L);

Expand Down
5 changes: 3 additions & 2 deletions src/LRequest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,10 @@ RegisterLuaRequest(lua_State *L)
}

Entity *
NewLuaRequest(lua_State *L, Entity &&src, const struct ucred &peer_cred)
NewLuaRequest(lua_State *L, lua_State *main_L,
Entity &&src, const struct ucred &peer_cred)
{
return LuaRequest::New(L, L, std::move(src), peer_cred);
return LuaRequest::New(L, main_L, std::move(src), peer_cred);
}

Entity &
Expand Down
8 changes: 7 additions & 1 deletion src/LRequest.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ struct Entity;
void
RegisterLuaRequest(lua_State *L);

/**
* @param L the lua_State on whose stack the new object will be pushed
* @param main_L the lua_State which is used to destruct Lua values
* owned by the new object
*/
Entity *
NewLuaRequest(lua_State *L, Entity &&src, const struct ucred &peer_cred);
NewLuaRequest(lua_State *L, lua_State *main_L,
Entity &&src, const struct ucred &peer_cred);

Entity &
CastLuaRequest(lua_State *L, int idx);

0 comments on commit aa2da29

Please sign in to comment.