Skip to content

Commit 10e56d7

Browse files
committed
tools/cve: Fix empty data dir case (envoyproxy#41313)
Signed-off-by: Ryan Northey <[email protected]>
1 parent 4b3dda3 commit 10e56d7

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
@@ -582,6 +582,8 @@ common:remote-envoy-engflow --config=rbe-envoy-engflow
582582
common:remote-cache-envoy-engflow --config=common-envoy-engflow
583583
common:remote-cache-envoy-engflow --config=cache-envoy-engflow
584584

585+
common:cves --//tools/dependency:cve-data=//tools/dependency:cve-data-dir
586+
585587
# Specifies the rustfmt.toml for all rustfmt_test targets.
586588
build --@rules_rust//rust/settings:rustfmt.toml=//:rustfmt.toml
587589

.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
@@ -155,11 +155,29 @@ envoy_genjson(
155155
)
156156

157157
filegroup(
158-
name = "cve-data",
158+
name = "cve-data-dir",
159159
srcs = glob(["cve_data/*.json"]),
160160
visibility = ["//visibility:public"],
161161
)
162162

163+
genrule(
164+
name = "placeholder",
165+
outs = ["PLACEHOLDER.txt"],
166+
cmd = "echo '' > $@",
167+
)
168+
169+
filegroup(
170+
name = "empty-directory",
171+
srcs = [":placeholder"], # default fallback
172+
visibility = ["//visibility:public"],
173+
)
174+
175+
label_flag(
176+
name = "cve-data",
177+
build_setting_default = ":empty-directory",
178+
visibility = ["//visibility:public"],
179+
)
180+
163181
sh_binary(
164182
name = "cves",
165183
srcs = ["cves.sh"],
@@ -195,6 +213,18 @@ genrule(
195213
export JQ_VERSION_UTILS="$(location :version.jq)"
196214
export CVES_IGNORED="$(location :ignored-cves.json)"
197215
export CVES="$(locations :cve-data)"
216+
read -ra CVELIST <<< "$$CVES"
217+
HAS_JSON=false
218+
for f in "$${CVELIST[@]}"; do
219+
if [[ "$$f" == *.json ]]; then
220+
HAS_JSON=true
221+
break
222+
fi
223+
done
224+
if [[ "$$HAS_JSON" != true ]]; then
225+
echo "No CVE data set, perhaps use --config=cves?" >&2
226+
exit 1
227+
fi
198228
$(location :cves) \
199229
> $@ || :
200230
""",

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)