rsyslog/tests/config-translate-yaml-to-rs.sh
Rainer Gerhards d53ffd7e48 grammar: fix YAML script buffer filename leak
Why:
ASan found a real leak in yaml-basic-yamlonly.sh. The translation tests
had been masking the same issue by disabling leak detection, which is
not acceptable for a real parser/loader bug.

Impact: YAML script-buffer loading now shuts down cleanly under ASan,
and the translation tests run without detect_leaks=0 overrides.

Before/After:
Before, YAML ruleset script loading leaked the top-level synthetic lexer
buffer name and tests suppressed leak detection. After, the leak is
freed in the lexer teardown path and the related tests run cleanly with
ASan leak detection enabled.

Technical Overview:
The YAML loader can push synthetic RainerScript buffers into the lexer
stack via cnfAddConfigBuffer().
For top-level synthetic buffers, yamlconf restores cnfcurrfn before the
lexer pop path runs, so the old top-level-name exception in popfile()
left the duplicated buffer name unreachable.
Adjust popfile() to free the top-level buffer name when cnfcurrfn no
longer points at that allocation, while preserving the normal top-level
file path ownership model.
Remove the temporary detect_leaks=0 overrides from the config-translate
shell tests now that the underlying leak is fixed.
Validate with yaml-basic-yamlonly.sh and the translation test set under
ASan.

With the help of AI-Agents: Codex
2026-04-03 17:19:49 +02:00

41 lines
949 B
Bash
Executable File

#!/bin/bash
# check canonical translation from YAML to RainerScript.
#
# Part of the testbench for rsyslog.
#
# This file is part of rsyslog.
# Released under ASL 2.0
. ${srcdir:=.}/diag.sh init
modpath="../runtime/.libs:../plugins/omstdout/.libs:../.libs"
cat > "${RSYSLOG_DYNNAME}.yaml" <<'YAML_EOF'
version: 2
modules:
- load: "omstdout"
mainqueue:
queue.type: "Direct"
rulesets:
- name: "main"
script: |
action(type="omstdout")
YAML_EOF
../tools/rsyslogd -N1 -f "${RSYSLOG_DYNNAME}.yaml" -F rainerscript -o "${RSYSLOG_DYNNAME}.out.conf" -M"$modpath"
cat > "${RSYSLOG_DYNNAME}.expected.conf" <<'RS_EOF'
main_queue(queue.type="Direct")
module(load="omstdout")
ruleset(name="main") {
action(type="omstdout")
}
RS_EOF
cmp_exact_file "${RSYSLOG_DYNNAME}.expected.conf" "${RSYSLOG_DYNNAME}.out.conf"
../tools/rsyslogd -N1 -f "${RSYSLOG_DYNNAME}.out.conf" -M"$modpath"
echo SUCCESS: YAML to RainerScript translation
exit_test