Teach the trailing-log gate to see command-substitution call sites

Found while fixing count_log_pattern: the gate reported that function clean
even though it ends in echo and both callers consume its status. Its call-site
patterns only matched direct forms -- if fn, while fn, fn ||, fn && -- so a
status consumed through command substitution was invisible, because the line
begins with the variable rather than the function name.

That is not an exotic form. It is how a shell function returns a value, and it
is precisely the shape of the swallowed-failure family this gate exists to
catch, so the gate was blind to a large part of its own stated class.

Three patterns added for the assignment, if-guarded and test-expression forms.
The extension finds four real instances, all value-returning helpers whose
trailing echo made their exit status unconditionally zero, and each now carries
an explicit return 0. Also corrects the finding message, which described the
trailing command as a log call; for these it is the return mechanism, and the
hazard is that it fixes the status either way.

Validated by breaking what it guards: a probe reintroducing the defect shape
behind a command substitution is reported and exits 1, where before the
extension it would have passed.
This commit is contained in:
Johnathan Corgan
2026-07-23 15:45:37 +00:00
parent bf173d8d98
commit d4a2504f99
5 changed files with 46 additions and 9 deletions
+1
View File
@@ -120,6 +120,7 @@ ping_path() {
return
fi
echo "${rtt//\// } ${loss:-N/A}"
return 0
}
# ── Path definitions ───────────────────────────────────────────────────────
@@ -74,6 +74,7 @@ docker_host_name() {
local host
host=$(get_node_attr "$topology_file" "$node_id" "docker_host")
echo "${host:-node-$node_id}"
return 0
}
# Get peers list from topology
@@ -118,6 +119,7 @@ get_default_transport() {
local topology_file="$1"
local transport=$(grep "^default_transport:" "$topology_file" | head -1 | sed 's/.*: *\([a-z]*\).*/\1/')
echo "${transport:-udp}"
return 0
}
# Get the port for a given transport type
+1
View File
@@ -159,6 +159,7 @@ build_netem_params() {
fi
echo "$params"
return 0
}
# Check if a container is running