Bug #9070
closedlua/config: log_path() leaks a _getcwd buffer per call on Windows
Description
- Status: present in
main(9b7938aec); Windows-only - Class: C-heap leak per call (unbounded, not accounted by the Lua sandbox)
- Component:
src/util-lua-config.c:36-43->src/util-conf.c:38-54(SCConfigGetLogDirectory)
Description¶
On Windows, when default-log-dir is not set, SCConfigGetLogDirectory() allocates a buffer per call:
if (SCConfGetNonNull("default-log-dir", &log_dir) != 1) {
#ifdef OS_WIN32
log_dir = _getcwd(NULL, 0); /* mallocs */
if (log_dir == NULL)
log_dir = DEFAULT_LOG_DIR;
#else
log_dir = DEFAULT_LOG_DIR;
#endif
}
return log_dir;
config.log_path() (src/util-lua-config.c:36-43) copies the string into Lua and then loses the pointer; no caller frees it and there is no ownership contract. Trigger: Windows + minimal config without -l/default-log-dir, a rule or output script calling config.log_path() per packet/event -> one leaked _getcwd buffer per call. The allocation is not routed through the sandbox allocator, so security.lua.max-bytes cannot bound it.
Fix direction¶
Cache/own the value (e.g. have SCConfigGetLogDirectory() cache the _getcwd result once, or make log_path() use a fixed buffer), or return DEFAULT_LOG_DIR on Windows too.
Test¶
Windows-gated lua-config-log-path-repeat or a C unit test with an allocation counter; POSIX behavior is unaffected.