]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1764 in SNORT/snort3 from ~MMATIRKO/snort3:luajit_segv to master
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Thu, 26 Sep 2019 19:20:52 +0000 (15:20 -0400)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Thu, 26 Sep 2019 19:20:52 +0000 (15:20 -0400)
Squashed commit of the following:

commit 5673dcacb025089db520ffcd8e87bf217ee59f8e
Author: Michael Matirko <mmatirko@cisco.com>
Date:   Tue Sep 24 13:36:00 2019 -0400

    lua: Added move constructor and move assignment operator to Lua::State to fix segv (CSCvn22329)

src/ips_options/ips_luajit.cc
src/lua/lua.cc
src/lua/lua.h

index c2da9ea40806b32a482d78183b8db0a021c7318c..78a34c887283a3d4304733038d9459acda496e62 100644 (file)
@@ -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);
index 9d3703a8aebd14a2df856a988f8f1281329ccc1f..0555858fb6e1b1b62bcc68bfd55eada937a21a06 100644 (file)
@@ -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()
 {
index 3a004a7d5f093ad4dae4c271bec1d90d076f6d46..f830fe466db79e33591ed78f78f512d58b6abf3f 100644 (file)
@@ -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; }