From: Otto Moerbeek Date: Fri, 1 Apr 2022 12:48:05 +0000 (+0200) Subject: Coverity: 1419402 Uncaught exception X-Git-Tag: rec-4.7.0-beta1~21^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=87b592685ad8c62746c53bdba5502fed98a0bdbd;p=thirdparty%2Fpdns.git Coverity: 1419402 Uncaught exception Catch any exception that might be thrown when (copy) constructing an object. As the push method is declared `noexcept` we cannot have that. --- diff --git a/ext/luawrapper/include/LuaContext.hpp b/ext/luawrapper/include/LuaContext.hpp index 9f8d473fb7..ad6c86e556 100644 --- a/ext/luawrapper/include/LuaContext.hpp +++ b/ext/luawrapper/include/LuaContext.hpp @@ -1639,12 +1639,18 @@ private: // writing structure for this type into the registry checkTypeRegistration(state, &typeid(TType)); + try { + // creating the object + // lua_newuserdata allocates memory in the internals of the lua library and returns it so we can fill it + // and that's what we do with placement-new + const auto pointerLocation = static_cast(lua_newuserdata(state, sizeof(TType))); + new (pointerLocation) TType(std::forward(value)); + } + catch (...) { + Pusher::push(state, std::current_exception()).release(); + luaError(state); + } - // creating the object - // lua_newuserdata allocates memory in the internals of the lua library and returns it so we can fill it - // and that's what we do with placement-new - const auto pointerLocation = static_cast(lua_newuserdata(state, sizeof(TType))); - new (pointerLocation) TType(std::forward(value)); PushedObject obj{state, 1}; // creating the metatable (over the object on the stack)