Skip to content

Commit 83a5ed5

Browse files
committed
tools/cve: Fix empty data dir case (#41313)
Signed-off-by: Ryan Northey <[email protected]>
1 parent 069c427 commit 83a5ed5

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ common:remote-envoy-engflow --config=rbe-envoy-engflow
554554
common:remote-cache-envoy-engflow --config=common-envoy-engflow
555555
common:remote-cache-envoy-engflow --config=cache-envoy-engflow
556556

557+
common:cves --//tools/dependency:cve-data=//tools/dependency:cve-data-dir
558+
557559
#############################################################################
558560
# debug: Various Bazel debugging flags
559561
#############################################################################

.github/workflows/_cve_scan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ jobs:
4242
"${{ steps.vars.outputs.cve-data-path }}"
4343
- name: Run CVE dependency scanner
4444
run: |
45-
bazel test --config=ci //tools/dependency:cve_test
45+
bazel test --config=ci --config=cves //tools/dependency:cve_test

tools/dependency/BUILD

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,29 @@ envoy_genjson(
150150
)
151151

152152
filegroup(
153-
name = "cve-data",
153+
name = "cve-data-dir",
154154
srcs = glob(["cve_data/*.json"]),
155155
visibility = ["//visibility:public"],
156156
)
157157

158+
genrule(
159+
name = "placeholder",
160+
outs = ["PLACEHOLDER.txt"],
161+
cmd = "echo '' > $@",
162+
)
163+
164+
filegroup(
165+
name = "empty-directory",
166+
srcs = [":placeholder"], # default fallback
167+
visibility = ["//visibility:public"],
168+
)
169+
170+
label_flag(
171+
name = "cve-data",
172+
build_setting_default = ":empty-directory",
173+
visibility = ["//visibility:public"],
174+
)
175+
158176
sh_binary(
159177
name = "cves",
160178
srcs = ["cves.sh"],
@@ -190,6 +208,18 @@ genrule(
190208
export JQ_VERSION_UTILS="$(location :version.jq)"
191209
export CVES_IGNORED="$(location :ignored-cves.json)"
192210
export CVES="$(locations :cve-data)"
211+
read -ra CVELIST <<< "$$CVES"
212+
HAS_JSON=false
213+
for f in "$${CVELIST[@]}"; do
214+
if [[ "$$f" == *.json ]]; then
215+
HAS_JSON=true
216+
break
217+
fi
218+
done
219+
if [[ "$$HAS_JSON" != true ]]; then
220+
echo "No CVE data set, perhaps use --config=cves?" >&2
221+
exit 1
222+
fi
193223
$(location :cves) \
194224
> $@ || :
195225
""",

tools/dependency/cves.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ JQ_VERSION_LIBDIR="$(dirname "$JQ_VERSION_UTILS")"
3131

3232
read -ra CVES <<< "$CVES"
3333

34+
for f in "${CVES[@]}"; do
35+
if [[ "$f" == *.json ]]; then
36+
HAS_JSON=true
37+
break
38+
fi
39+
done
40+
if [[ "$HAS_JSON" != true ]]; then
41+
echo "No CVE data set, perhaps use --config=cves?" >&2
42+
exit 1
43+
fi
44+
3445
parse_cves () {
3546
# Stream the cves checking against the deps and then slurp the results into a single json object
3647
# cat "${CVEPATH}/"*.json \

0 commit comments

Comments
 (0)