Skip to content

Commit 01cf2ae

Browse files
committed
Fix variable quoting to prevent word splitting
This properly quotes all variable expansions and uses bash arrays for file lists to prevent word splitting issues: - Use mapfile to populate SOURCES array instead of command substitution - Quote all command substitutions and variable assignments - Use "${SOURCES[@]}" for proper array expansion - Quote exit codes and function parameters
1 parent e608950 commit 01cf2ae

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

.ci/check-format.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
set -euo pipefail
44

5-
SOURCES=$(git ls-files '*.c' '*.cxx' '*.cpp' '*.h' '*.hpp')
5+
# Get list of source files into array
6+
mapfile -t SOURCES < <(git ls-files '*.c' '*.cxx' '*.cpp' '*.h' '*.hpp')
67

78
# Use clang-format dry-run mode with --Werror to fail on format violations
89
# This eliminates the need for temporary files and manual diff comparisons
9-
clang-format-18 -n --Werror ${SOURCES}
10+
clang-format-18 -n --Werror "${SOURCES[@]}"

.ci/common.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
set -euo pipefail
55

66
# Detect platform
7-
MACHINE_TYPE=$(uname -m)
8-
OS_TYPE=$(uname -s)
7+
MACHINE_TYPE="$(uname -m)"
8+
OS_TYPE="$(uname -s)"
99

1010
# Cleanup function - kills all semu processes
1111
cleanup() {
@@ -22,14 +22,14 @@ ASSERT() {
2222
local exit_code
2323

2424
set +e
25-
cmd_output=$("$@" 2>&1)
25+
cmd_output="$("$@" 2>&1)"
2626
exit_code=$?
2727
set -e
2828

29-
if [ $exit_code -ne 0 ]; then
29+
if [ "$exit_code" -ne 0 ]; then
3030
echo "Assert failed: $*" >&2
3131
echo "Output: $cmd_output" >&2
32-
exit $exit_code
32+
exit "$exit_code"
3333
fi
3434
}
3535

@@ -59,7 +59,7 @@ get_timeout() {
5959
}
6060

6161
# Export TIMEOUT for use in scripts
62-
TIMEOUT=$(get_timeout)
62+
TIMEOUT="$(get_timeout)"
6363
export TIMEOUT
6464

6565
# Color codes for output

.ci/test-netdev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ esac
2020

2121
# Test network device functionality
2222
TEST_NETDEV() {
23-
local NETDEV=$1
23+
local NETDEV="$1"
2424
local CMD_PREFIX=""
2525

2626
if [ "$NETDEV" == "tap" ]; then

.github/workflows/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,20 @@ jobs:
111111
run: |
112112
set -euo pipefail
113113
114-
# Get list of source files
115-
SOURCES=$(git ls-files '*.c' '*.cxx' '*.cpp' '*.h' '*.hpp')
114+
# Get list of source files into array
115+
mapfile -t SOURCES < <(git ls-files '*.c' '*.cxx' '*.cpp' '*.h' '*.hpp')
116116
117117
# Register cleanup function to restore files on exit
118118
cleanup_files() {
119-
if [ -n "${SOURCES:-}" ]; then
119+
if [ ${#SOURCES[@]} -gt 0 ]; then
120120
echo "Restoring files to original state..."
121-
git checkout -- ${SOURCES} 2>/dev/null || true
121+
git checkout -- "${SOURCES[@]}" 2>/dev/null || true
122122
fi
123123
}
124124
trap cleanup_files EXIT INT TERM
125125
126126
# Apply clang-format in-place to generate diff
127-
clang-format-18 -i ${SOURCES}
127+
clang-format-18 -i "${SOURCES[@]}"
128128
129129
# Generate diff and pipe to reviewdog
130130
# Note: reviewdog exit code doesn't affect cleanup due to trap

0 commit comments

Comments
 (0)