Bug #9071
closedlua: memory_limit_error is never cleared -> later errors misreported as memory-limit
Description
- Status: present in
main(9b7938aec); code-confirmed - Class: error misclassification / stats corruption (diagnostics only, no memory safety)
- Component:
src/util-lua-sandbox.c,src/detect-lua.c
Description¶
memory_limit_error is set by the sandbox allocator (src/util-lua-sandbox.c:70 for new allocations, :86 for reallocations) and is never cleared:
SCLuaSbResetInstructionCounter()clearsblocked_function_errorandinstruction_count_error(util-lua-sandbox.c:426-427) but notmemory_limit_error;- no other site resets it.
DetectLuaRunMatch() classifies an error by checking the flags in order (detect-lua.c:180-190):
if (context->blocked_function_error) { ... }
else if (context->instruction_count_error) { ... }
else if (context->memory_limit_error) {
StatsCounterIncr(..., det_ctx->lua_memory_limit_errors);
reason = "memory limit exceeded";
...
}
Once a script has hit the memory limit even once, every subsequent error in that state - blocked function, script bug, real memory-limit - is reported as "memory limit exceeded", counted in detect.lua.memory_limit_errors, and the real Lua error text is discarded. Diagnostics for long-lived states are therefore wrong after the first such event.
Fix direction¶
Clear memory_limit_error in the per-call reset (SCLuaSbResetInstructionCounter) after classification has consumed it, i.e. treat the three flags consistently:
sb->blocked_function_error = false;
sb->instruction_count_error = false;
sb->memory_limit_error = false;
Regression test¶
lua-memory-error-sticky: trigger a memory-limit error once, then induce an unrelated script error; assert the second error is reported/counted as a generic script error, not a memory-limit error.