Skip to content

Commit

Permalink
LMail: 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 b67a7bb commit fffb729
Show file tree
Hide file tree
Showing 4 changed files with 12 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-qrelay (0.25) unstable; urgency=low

*
* fix use-after-free crash bug

--

Expand Down
2 changes: 1 addition & 1 deletion src/Connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ QmqpRelayConnection::OnRequest(AllocatedArray<std::byte> &&payload)

handler->Push(L);

NewLuaMail(L, std::move(mail), peer_cred);
NewLuaMail(L, GetMainState(), std::move(mail), peer_cred);

Resume(L, 1);
}
Expand Down
5 changes: 3 additions & 2 deletions src/LMail.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,10 @@ RegisterLuaMail(lua_State *L)
}

MutableMail *
NewLuaMail(lua_State *L, MutableMail &&src, const struct ucred &peer_cred)
NewLuaMail(lua_State *L, lua_State *main_L,
MutableMail &&src, const struct ucred &peer_cred)
{
return LuaMail::New(L, L, std::move(src), peer_cred);
return LuaMail::New(L, main_L, std::move(src), peer_cred);
}

MutableMail &
Expand Down
8 changes: 7 additions & 1 deletion src/LMail.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ struct MutableMail;
void
RegisterLuaMail(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
*/
MutableMail *
NewLuaMail(lua_State *L, MutableMail &&src, const struct ucred &peer_cred);
NewLuaMail(lua_State *L, lua_State *main_L,
MutableMail &&src, const struct ucred &peer_cred);

MutableMail &
CastLuaMail(lua_State *L, int idx);
Expand Down

0 comments on commit fffb729

Please sign in to comment.