Skip to content

Commit 41d664a

Browse files
committed
added test case name validation to benchmark.sh, added additional sanity check to aggregate/action.yml
1 parent 2433d88 commit 41d664a

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

devops/actions/benchmarking/aggregate/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ runs:
2626
shell: bash
2727
run: |
2828
# DO NOT use inputs.lookback_days directly, only use SANITIZED_TIMESTAMP.
29-
SANITIZED_LOOKBACK_DAYS="$(echo '${{ inputs.lookback_days }}' | grep -oE "^[0-9]+$")"
29+
SANITIZED_LOOKBACK_DAYS="$(echo '${{ inputs.lookback_days }}' | grep -oE '^[0-9]+$')"
3030
if [ -z "$SANITIZED_LOOKBACK_DAYS" ]; then
3131
echo "Please ensure inputs.lookback_days is a number."
3232
exit 1
3333
fi
3434
SANITIZED_TIMESTAMP="$(date -d "$SANITIZED_LOOKBACK_DAYS days ago" +%Y%m%d_%H%M%S)"
35+
if [ -z "$(echo "$SANITIZED_TIMESTAMP" | grep -oE '^[0-9]{8}_[0-9]{6}$' )" ]; then
36+
echo "Invalid timestamp generated: is inputs.lookback_days valid?"
37+
exit 1
38+
fi
3539
echo "SANITIZED_TIMESTAMP=$SANITIZED_TIMESTAMP" >> $GITHUB_ENV
3640
- name: Load benchmarking configuration
3741
shell: bash

devops/scripts/benchmarking/benchmark.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ This script builds and runs benchmarks from compute-benchmarks."
1515
exit 1
1616
}
1717

18+
# Ensures test cases read from enabled_tests.conf contains no malicious content
19+
_validate_testname () {
20+
if [ -n "$(printf "%s" "$1" | sed "s/[a-zA-Z_]*//g")" ]; then
21+
echo "Illegal characters in $TEST_CONFIG. Permitted characters: a-zA-Z_"
22+
exit 1
23+
fi
24+
}
25+
1826
clone_perf_res() {
1927
echo "### Cloning llvm-ci-perf-results ($SANITIZED_PERF_RES_GIT_REPO:$SANITIZED_PERF_RES_GIT_BRANCH) ###"
2028
git clone -b "$SANITIZED_PERF_RES_GIT_BRANCH" "https://github.com/$SANITIZED_PERF_RES_GIT_REPO" ./llvm-ci-perf-results
@@ -43,11 +51,7 @@ build_compute_bench() {
4351
# Skip lines starting with '#'
4452
[ "${case##\#*}" ] || continue
4553

46-
if [ -n "$(printf "%s" "$case" | sed "s/[a-zA-Z_]*//g")" ]; then
47-
echo "Illegal characters in $TESTS_CONFIG."
48-
exit 1
49-
fi
50-
# TODO Sanitize this
54+
_validate_testname "$case"
5155
make "-j$SANITIZED_COMPUTE_BENCH_COMPILE_JOBS" "$case"
5256
done < "$TESTS_CONFIG"
5357
fi
@@ -117,11 +121,7 @@ process_benchmarks() {
117121
# Loop through each line of enabled_tests.conf, but ignore lines in the
118122
# test config starting with #'s:
119123
grep "^[^#]" "$TESTS_CONFIG" | while read -r testcase; do
120-
# Make sure testcase is clean:
121-
if [ -n "$(printf "%s" "$testcase" | sed "s/[a-zA-Z_]*//g")" ]; then
122-
echo "Illegal characters in $TESTS_CONFIG."
123-
exit 1
124-
fi
124+
_validate_testname "$testcase"
125125
echo "# Running $testcase..."
126126

127127
# The benchmark results git repo and this script's output both share

0 commit comments

Comments
 (0)