From bd9fa88d2aa5fe7b3848806d93dfcc40fbc03c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Arroba?= <19954079+cesararroba@users.noreply.github.com> Date: Fri, 31 Jul 2026 13:09:58 +0200 Subject: [PATCH] fix(ci): harden osv-scan.sh against a missing osv-scanner.toml (#12267) --- .github/scripts/osv-scan.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/scripts/osv-scan.sh b/.github/scripts/osv-scan.sh index 16afc6668c..2e24b19630 100755 --- a/.github/scripts/osv-scan.sh +++ b/.github/scripts/osv-scan.sh @@ -51,7 +51,8 @@ STDERR="$(mktemp)" trap 'rm -f "${STDERR}"' EXIT set +e -OUTPUT="$(osv-scanner scan source "${SCAN_ARGS[@]}" --format=json "$@" 2>"${STDERR}")" +# ${a[@]+...} guard: an empty array trips `set -u` on bash before 4.4. +OUTPUT="$(osv-scanner scan source ${SCAN_ARGS[@]+"${SCAN_ARGS[@]}"} --format=json "$@" 2>"${STDERR}")" RC=$? set -e @@ -100,6 +101,8 @@ FINDINGS="$(printf '%s' "${OUTPUT}" | jq --argjson sevs "${SEVERITY_JSON}" ' ] ')" +# jq exits 0 with no output on empty stdin, but non-zero on malformed JSON. +# Let the failure abort under set -e rather than reporting zero findings. COUNT="$(printf '%s' "${FINDINGS}" | jq 'length')" # Write the findings JSON to OSV_REPORT_FILE so callers (e.g. the composite @@ -108,7 +111,7 @@ if [ -n "${OSV_REPORT_FILE:-}" ]; then printf '%s' "${FINDINGS}" > "${OSV_REPORT_FILE}" fi -if [ "${COUNT}" -gt 0 ]; then +if [ "${COUNT:-0}" -gt 0 ]; then echo "osv-scanner: ${COUNT} finding(s) at severity ${SEVERITY_LEVELS}" printf '%s' "${FINDINGS}" | jq -r ' .[] | " [\(.severity)\(if .score then " \(.score)" else "" end)] \(.id) \(.ecosystem)/\(.package)@\(.version) — \(.summary // "(no summary)")"