--- /dev/null
+Test that directly calling the metatable garbard collector doesn't crash
+Suricata. This requires disabling the sandbox, but we are still able to guard
+against it.
+
+https://redmine.openinfosecfoundation.org/issues/8248
--- /dev/null
+local sf = require "suricata.flow"
+
+function init(args)
+ local needs = {}
+ needs["packet"] = "true"
+ return needs
+end
+
+function match(args)
+ -- 1. Get a valid flow object
+ local f = sf.get()
+
+ if f then
+ -- 2. Access its metatable
+ local mt = getmetatable(f)
+
+ if mt and mt.__gc then
+ -- 3. Manually call __gc with nil to trigger the crash
+ mt.__gc(nil)
+ end
+ end
+ return 1
+end
--- /dev/null
+alert ip any any -> any any (msg:"Lua GC nil crash"; lua:test.lua; sid:1; rev:1;)
--- /dev/null
+requires:
+ min-version: 9.0.0
+
+args:
+ - --set default-rule-path=${TEST_DIR}
+ - --set security.lua.allow-restricted-functions=true
+
+pcap: ../lua-bad-script/test.pcap
+
+checks:
+ - filter:
+ count: 8
+ match:
+ event_type: alert
+ alert.signature_id: 1