Skip to content

Commit af03cae

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

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
@@ -154,11 +154,29 @@ envoy_genjson(
154154
)
155155

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

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

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)