netbox: fix memory corruption in net.box module
There was a bug in the netbox module related to access to previously released memory. To understand the essence of error, you need to understand how GC works in Lua: - GC checks the reachability of objects in Lua in one cycle and cleans out those that were unreachable. - Lua GC object is an entity whose memory is managed by the GC, for example: table, function, userdata, cdata. In our case it's cdata object, with struct error payload. - ffi.gc allows us to clean up Lua GC object payload at the time of deleting the GC object. - Finalizer in ffi.gc is hung on the Lua GC object. So after ffi.cast in our case first err object becomes unreachable. It will be cleaned after some time and if finalizer hangs on it, payload will also be cleaned. So payload in new err object (struct error in our case) becomes invalid.
Showing
- changelogs/unreleased/fix-netbox-memory-corruption.md 4 additions, 0 deletionschangelogs/unreleased/fix-netbox-memory-corruption.md
- src/box/lua/net_box.lua 1 addition, 1 deletionsrc/box/lua/net_box.lua
- test/box/net.box_memory_corruption.result 56 additions, 0 deletionstest/box/net.box_memory_corruption.result
- test/box/net.box_memory_corruption.test.lua 30 additions, 0 deletionstest/box/net.box_memory_corruption.test.lua
test/box/net.box_memory_corruption.result
0 → 100644
test/box/net.box_memory_corruption.test.lua
0 → 100644
Please register or sign in to comment