From c0991336bb51fdddb64565abe53191cdb13565ab Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Tue, 3 Feb 2026 05:15:27 +0100 Subject: [PATCH] fix(mitmproxy): Fix JSON output corruption from grep -c exit codes grep -c returns exit code 1 when no matches found (even though it outputs 0), causing `|| echo 0` to append an extra 0 and corrupt the JSON response. This broke ubus calls and LuCI status display. Use `: ${var:=0}` pattern instead to provide defaults. Co-Authored-By: Claude Opus 4.5 --- .../luci-app-mitmproxy/root/usr/libexec/rpcd/luci.mitmproxy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package/secubox/luci-app-mitmproxy/root/usr/libexec/rpcd/luci.mitmproxy b/package/secubox/luci-app-mitmproxy/root/usr/libexec/rpcd/luci.mitmproxy index 84548672..fb2f799c 100755 --- a/package/secubox/luci-app-mitmproxy/root/usr/libexec/rpcd/luci.mitmproxy +++ b/package/secubox/luci-app-mitmproxy/root/usr/libexec/rpcd/luci.mitmproxy @@ -67,7 +67,8 @@ get_status() { local threats_log="${data_path:-/srv/mitmproxy}/threats.log" if [ -f "$threats_log" ]; then local today=$(date -u +%Y-%m-%d) - threats_today=$(grep -c "\"timestamp\": \"$today" "$threats_log" 2>/dev/null || echo 0) + threats_today=$(grep -c "\"timestamp\": \"$today" "$threats_log" 2>/dev/null) + : ${threats_today:=0} fi # Count processed autobans @@ -77,7 +78,8 @@ get_status() { if [ -f "$autoban_log" ]; then autobans_total=$(wc -l < "$autoban_log" 2>/dev/null || echo 0) local today=$(date +%Y-%m-%d) - autobans_today=$(grep -c "^$today" "$autoban_log" 2>/dev/null || echo 0) + autobans_today=$(grep -c "^$today" "$autoban_log" 2>/dev/null) + : ${autobans_today:=0} fi # Pending autoban requests