fix: sanitize _mtime with tr to prevent ash arithmetic crash on Synology

stat output can include non-numeric chars on some RT2600ac firmware versions,
causing 0 to fail. Strip with tr -cd '0-9' before arithmetic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 03:29:10 +00:00
parent a4ba9f8fcd
commit 8f2d6a7cbd
@@ -207,6 +207,7 @@ _detect_wan_roles() {
_aiwanbal_available() { _aiwanbal_available() {
[ -d "$AIWANBAL_DIR" ] || return 1 [ -d "$AIWANBAL_DIR" ] || return 1
_mtime=$(stat -c %Y "${AIWANBAL_DIR}/wan1_score_avg" 2>/dev/null || stat -f %m "${AIWANBAL_DIR}/wan1_score_avg" 2>/dev/null) _mtime=$(stat -c %Y "${AIWANBAL_DIR}/wan1_score_avg" 2>/dev/null || stat -f %m "${AIWANBAL_DIR}/wan1_score_avg" 2>/dev/null)
_mtime=$(printf '%s' "$_mtime" | tr -cd '0-9')
[ -n "$_mtime" ] || return 1 [ -n "$_mtime" ] || return 1
_now=$(date +%s) _now=$(date +%s)
_age=$(( _now - _mtime )) _age=$(( _now - _mtime ))
@@ -415,6 +416,7 @@ _cached_speedtest() {
_f="${STATE_DIR}/speedtest-result-${_iface}" _f="${STATE_DIR}/speedtest-result-${_iface}"
[ -f "$_f" ] || return 1 [ -f "$_f" ] || return 1
_mtime=$(stat -c %Y "$_f" 2>/dev/null || stat -f %m "$_f" 2>/dev/null) _mtime=$(stat -c %Y "$_f" 2>/dev/null || stat -f %m "$_f" 2>/dev/null)
_mtime=$(printf '%s' "$_mtime" | tr -cd '0-9')
[ -n "$_mtime" ] || return 1 [ -n "$_mtime" ] || return 1
_st_now=$(date +%s) _st_now=$(date +%s)
_age=$(( _st_now - _mtime )) _age=$(( _st_now - _mtime ))