From: Vsevolod Stakhov Date: Fri, 17 Oct 2025 13:48:17 +0000 (+0100) Subject: [Test] Use safer AWK variable passing to prevent syntax errors X-Git-Tag: 3.14.0~67^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=437d56bf6be5188a82b74a574c5fe503c810828c;p=thirdparty%2Frspamd.git [Test] Use safer AWK variable passing to prevent syntax errors - Validate all count variables are numeric using grep - Use awk -v to pass variables instead of bash substitution - This prevents syntax errors when jq returns non-numeric values --- diff --git a/test/integration/scripts/integration-test.sh b/test/integration/scripts/integration-test.sh index c362cc7f99..85b57b3628 100755 --- a/test/integration/scripts/integration-test.sh +++ b/test/integration/scripts/integration-test.sh @@ -192,15 +192,16 @@ if [ "$TOTAL" -eq 0 ]; then exit 1 fi -# Ensure counts are numeric (default to 0 if empty) -FUZZY_COUNT=${FUZZY_COUNT:-0} -BAYES_SPAM_COUNT=${BAYES_SPAM_COUNT:-0} -BAYES_HAM_COUNT=${BAYES_HAM_COUNT:-0} - -# Calculate percentages using awk -FUZZY_RATE=$(awk "BEGIN {printf \"%.1f\", ($FUZZY_COUNT / $TOTAL) * 100}") -BAYES_SPAM_RATE=$(awk "BEGIN {printf \"%.1f\", ($BAYES_SPAM_COUNT / $TOTAL) * 100}") -BAYES_HAM_RATE=$(awk "BEGIN {printf \"%.1f\", ($BAYES_HAM_COUNT / $TOTAL) * 100}") +# Ensure counts are numeric (default to 0 if empty or non-numeric) +FUZZY_COUNT=$(echo "$FUZZY_COUNT" | grep -E '^[0-9]+$' || echo 0) +BAYES_SPAM_COUNT=$(echo "$BAYES_SPAM_COUNT" | grep -E '^[0-9]+$' || echo 0) +BAYES_HAM_COUNT=$(echo "$BAYES_HAM_COUNT" | grep -E '^[0-9]+$' || echo 0) +TOTAL=$(echo "$TOTAL" | grep -E '^[0-9]+$' || echo 0) + +# Calculate percentages using awk (pass variables safely) +FUZZY_RATE=$(awk -v count="$FUZZY_COUNT" -v total="$TOTAL" 'BEGIN {printf "%.1f", (count / total) * 100}') +BAYES_SPAM_RATE=$(awk -v count="$BAYES_SPAM_COUNT" -v total="$TOTAL" 'BEGIN {printf "%.1f", (count / total) * 100}') +BAYES_HAM_RATE=$(awk -v count="$BAYES_HAM_COUNT" -v total="$TOTAL" 'BEGIN {printf "%.1f", (count / total) * 100}') echo "Total scanned: $TOTAL" echo "Fuzzy detections: $FUZZY_COUNT ($FUZZY_RATE%)"