Skip to content

Commit 37bb4a3

Browse files
committed
tools/cve: Fix empty data dir case (#41313)
Signed-off-by: Ryan Northey <[email protected]>
1 parent 75c99a9 commit 37bb4a3

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
@@ -579,6 +579,8 @@ common:remote-envoy-engflow --config=rbe-envoy-engflow
579579
common:remote-cache-envoy-engflow --config=common-envoy-engflow
580580
common:remote-cache-envoy-engflow --config=cache-envoy-engflow
581581

582+
common:cves --//tools/dependency:cve-data=//tools/dependency:cve-data-dir
583+
582584
# Specifies the rustfmt.toml for all rustfmt_test targets.
583585
build --@rules_rust//rust/settings:rustfmt.toml=//:rustfmt.toml
584586

.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
@@ -152,11 +152,29 @@ envoy_genjson(
152152
)
153153

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

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

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)