88# Vulnerabilities and warnings which do not stem from direct
99# dependencies show the full dependency tree for the affected package.
1010
11- set -uo pipefail
11+ set -euo pipefail
1212
1313# Check if `cargo-audit`, `cargo-rbmt`, `jq`, and `python3` are installed
1414command -v cargo-audit > /dev/null 2>&1 || { echo " cargo-audit was not found on \$ PATH" ; exit 1; }
@@ -17,6 +17,7 @@ command -v jq >/dev/null 2>&1 || { echo "jq was not found on \$PATH"; exit 1; }
1717command -v python3 > /dev/null 2>&1 || { echo " python3 was not found on \$ PATH" ; exit 1; }
1818
1919WARNING_COUNTER=0
20+ WARNING_FAILURE_COUNTER=0
2021VULNERABILITY_COUNTER=0
2122
2223LOCKFILES=(" Cargo.lock" " Cargo-recent.lock" " Cargo-minimal.lock" )
@@ -141,10 +142,17 @@ format_findings() {
141142 local package_name
142143 local package_version
143144 local title
144- advisory_id=$( echo " $finding " | jq -r ' .advisory.id' )
145+ advisory_id=$( echo " $finding " | jq -r ' .advisory.id // (.kind | ascii_upcase) // "UNKNOWN" ' )
145146 package_name=$( echo " $finding " | jq -r ' .package.name' )
146147 package_version=$( echo " $finding " | jq -r ' .package.version' )
147- title=$( echo " $finding " | jq -r ' .advisory.title' )
148+ title=$( echo " $finding " | jq -r '
149+ .advisory.title //
150+ if .kind == "yanked" then
151+ "crate version was yanked"
152+ else
153+ "non-advisory cargo-audit warning"
154+ end
155+ ' )
148156
149157 local branch
150158 local branch_transitive
@@ -170,6 +178,8 @@ format_findings() {
170178
171179 [ " $index " -lt $(( total - 1 )) ] && echo " ${indent} │"
172180 done
181+
182+ return 0
173183}
174184
175185# Copy the given lockfile to `Cargo.lock`, run `cargo audit`,
@@ -183,14 +193,22 @@ process_lockfile() {
183193
184194 local audit_output
185195 audit_output=$( cargo audit --json 2> /dev/null) || true
196+ if [ -z " $audit_output " ] || ! jq -e . > /dev/null <<< " $audit_output" ; then
197+ echo " cargo audit failed for $lockfile " >&2
198+ exit 1
199+ fi
186200
187201 local vulnerabilities
188202 vulnerabilities=$( echo " $audit_output " | jq ' .vulnerabilities.count // 0' )
189203
190204 local warnings
191205 warnings=$( echo " $audit_output " | jq ' [.warnings | to_entries[] | .value | length] | add // 0' )
192206
207+ local warning_failures
208+ warning_failures=$( echo " $audit_output " | jq ' [.warnings | to_entries[] | .value[] | select(.kind != "yanked")] | length' )
209+
193210 WARNING_COUNTER=$(( WARNING_COUNTER + warnings))
211+ WARNING_FAILURE_COUNTER=$(( WARNING_FAILURE_COUNTER + warning_failures))
194212 VULNERABILITY_COUNTER=$(( VULNERABILITY_COUNTER + vulnerabilities))
195213
196214 WARNING_COUNT[$lockfile ]=$warnings
@@ -250,7 +268,7 @@ process_lockfile "Cargo-minimal.lock"
250268
251269echo " "
252270
253- if [ " $WARNING_COUNTER " -gt 0 ] || [ " $VULNERABILITY_COUNTER " -gt 0 ]; then
271+ if [ " $WARNING_FAILURE_COUNTER " -gt 0 ] || [ " $VULNERABILITY_COUNTER " -gt 0 ]; then
254272 echo " > Audit Status: FAILED"
255273else
256274 echo " > Audit Status: SUCCESS"
@@ -282,6 +300,6 @@ for ((i=0; i<lockfile_total; i++)); do
282300 fi
283301done
284302
285- if [ " $WARNING_COUNTER " -gt 0 ] || [ " $VULNERABILITY_COUNTER " -gt 0 ]; then
303+ if [ " $WARNING_FAILURE_COUNTER " -gt 0 ] || [ " $VULNERABILITY_COUNTER " -gt 0 ]; then
286304 exit 1
287305fi
0 commit comments