fix(wake): #943 whole-string validation for WAKE_SNAPSHOT_TS_FUTURE_SLACK + version 0.6.13
grep is line-oriented, so a multi-line knob value passed the per-line anchors and was still fatal in arithmetic. Replaced with a case pattern matching the whole string, so an embedded or leading newline rejects. Manifest bumped 0.6.12 -> 0.6.13: three materially different detectors had shipped under one version string, and version= is the component sole self-identity claim. Authored-by: pepper Reviewed-by: mos-dt (independent, at this head; transfer proven by blob-hash equality) Merged-by: Mos Co-authored-by: mos-dt-0 <[email protected]>
This commit was merged in pull request #943.
This commit is contained in:
@@ -295,16 +295,24 @@ _poll_source() {
|
||||
# is interpolated into $((...)) under set -u, so a non-numeric value
|
||||
# ('300s', '5m', 'abc') would be FATAL to the poll — the one thing this
|
||||
# block must never be. Resolve it ONCE, validate, fall back loudly.
|
||||
local now_s slack
|
||||
local now_s slack slack_ok
|
||||
slack="${WAKE_SNAPSHOT_TS_FUTURE_SLACK:-300}"
|
||||
if ! printf '%s' "$slack" | grep -Eq '^[0-9]{1,9}$'; then
|
||||
echo "detector.sh: WAKE_SNAPSHOT_TS_FUTURE_SLACK='$slack' is not a plain non-negative integer (seconds) — falling back to 300, poll continues (#940)." >&2
|
||||
# NOT grep: grep is LINE-oriented, so ^...$ anchors bind per line and a
|
||||
# multi-line value ($'300\n8') passes the regex yet is FATAL in $((...)).
|
||||
# The case pattern matches the WHOLE string, newlines included. (snap_ts
|
||||
# is immune: jq's number type-check above cannot emit an embedded newline.)
|
||||
case "$slack" in
|
||||
'' | *[!0-9]*) slack_ok=1 ;;
|
||||
*) [ "${#slack}" -le 9 ] && slack_ok=0 || slack_ok=1 ;;
|
||||
esac
|
||||
if [ "$slack_ok" -ne 0 ]; then
|
||||
echo "detector.sh: WAKE_SNAPSHOT_TS_FUTURE_SLACK='$slack' is not a plain non-negative integer of at most 9 digits (seconds) — falling back to 300, poll continues (#940)." >&2
|
||||
slack=300
|
||||
fi
|
||||
# Shape validation is not radix validation: bash reads a leading zero as
|
||||
# OCTAL, so '08'/'09' pass the regex yet are FATAL in $((...)), and
|
||||
# OCTAL, so '08'/'09' pass the shape check yet are FATAL in $((...)), and
|
||||
# '0300' silently means 192. Force base-10 so the knob means what the
|
||||
# operator wrote (safe: the regex above guarantees pure digits).
|
||||
# operator wrote (safe: the case pattern above guarantees pure digits).
|
||||
slack=$((10#$slack))
|
||||
now_s="$(date +%s)"
|
||||
if [ "$snap_ts" -gt $((now_s + slack)) ]; then
|
||||
|
||||
Reference in New Issue
Block a user