From: Mike Stepanek (mstepane) Date: Thu, 26 Sep 2019 19:20:52 +0000 (-0400) Subject: Merge pull request #1764 in SNORT/snort3 from ~MMATIRKO/snort3:luajit_segv to master X-Git-Tag: 3.0.0-262~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69c0167740e9da079467a306ca7238e25fe7a541;p=thirdparty%2Fsnort3.git Merge pull request #1764 in SNORT/snort3 from ~MMATIRKO/snort3:luajit_segv to master Squashed commit of the following: commit 5673dcacb025089db520ffcd8e87bf217ee59f8e Author: Michael Matirko Date: Tue Sep 24 13:36:00 2019 -0400 lua: Added move constructor and move assignment operator to Lua::State to fix segv (CSCvn22329) --- diff --git a/src/ips_options/ips_luajit.cc b/src/ips_options/ips_luajit.cc index c2da9ea40..78a34c887 100644 --- a/src/ips_options/ips_luajit.cc +++ b/src/ips_options/ips_luajit.cc @@ -142,7 +142,8 @@ LuaJitOption::LuaJitOption( config += "}"; unsigned max = ThreadConfig::get_instance_max(); - + states.reserve(max); + for ( unsigned i = 0; i < max; ++i ) { states.emplace_back(true); diff --git a/src/lua/lua.cc b/src/lua/lua.cc index 9d3703a8a..0555858fb 100644 --- a/src/lua/lua.cc +++ b/src/lua/lua.cc @@ -41,8 +41,23 @@ State::State(bool openlibs) luaL_openlibs(state); } -State::State(State&& o) : - state { std::move(o.state) } { } +State& State::operator=(State&& o) +{ + if (this != &o) + { + if (state) + lua_close(state); + state = o.state; + o.state = nullptr; + } + return *this; +} + +State::State(State&& o) noexcept +{ + state = o.state; + o.state = NULL; +} State::~State() { diff --git a/src/lua/lua.h b/src/lua/lua.h index 3a004a7d5..f830fe466 100644 --- a/src/lua/lua.h +++ b/src/lua/lua.h @@ -36,10 +36,12 @@ public: State(bool openlibs = true); ~State(); - State(State&) = delete; + State(State&) = delete; + State& operator=(State&) = delete; // Enable move constructor - State(State&& other); + State(State&&) noexcept; + State& operator=(State&&); lua_State* get_ptr() { return state; }