-
Notifications
You must be signed in to change notification settings - Fork 0
228 lines (196 loc) · 6.29 KB
/
Copy pathci.yml
File metadata and controls
228 lines (196 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: CI
on:
push:
branches:
- main
- master
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache
DEFAULT_CFLAGS: >-
-Wall -Wextra -Werror -O2 -g
-fstack-protector-strong -D_FORTIFY_SOURCE=2
DEFAULT_VERIFY_CFLAGS: >-
-Wall -Wextra -Werror -O2
-fstack-protector-strong -D_FORTIFY_SOURCE=2
SANITIZER_CFLAGS: >-
-Wall -Wextra -Werror -O1 -g
-fsanitize=address,undefined -fno-omit-frame-pointer
jobs:
lint:
name: Lint and static analysis
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install linting tools
run: |
sudo apt-get update
sudo apt-get install -y clang-format cppcheck
- name: Verify formatting with clang-format
shell: bash
run: |
mapfile -t files < <(find src tests -type f \( -name '*.c' -o -name '*.h' \) | sort)
if [ "${#files[@]}" -eq 0 ]; then
echo "No C source files found to format-check."
exit 0
fi
clang-format --version
clang-format \
--style=file \
--fallback-style=LLVM \
--dry-run \
--Werror \
"${files[@]}"
- name: Run cppcheck
shell: bash
run: |
cppcheck \
--std=c11 \
--language=c \
--enable=warning,style,performance,portability \
--error-exitcode=1 \
--inline-suppr \
--suppress=missingIncludeSystem \
src tests
build-test:
name: Build and test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: lint
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
install_cmd: |
sudo apt-get update
sudo apt-get install -y gcc make ccache
- os: macos-latest
install_cmd: |
brew update
brew install gcc make ccache
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install build dependencies
run: ${{ matrix.install_cmd }}
- name: Resolve toolchain
shell: bash
run: |
if [ "${{ runner.os }}" = "macOS" ]; then
CC_BIN="$(command -v gcc-14 || command -v gcc-13 || command -v gcc-12)"
MAKE_BIN="$(command -v gmake)"
BUILD_CFLAGS="-Wall -Wextra -Werror -O2 -g -fstack-protector-strong"
BUILD_VERIFY_CFLAGS="-Wall -Wextra -Werror -O2 -fstack-protector-strong"
else
CC_BIN="$(command -v gcc)"
MAKE_BIN="$(command -v make)"
BUILD_CFLAGS="${DEFAULT_CFLAGS}"
BUILD_VERIFY_CFLAGS="${DEFAULT_VERIFY_CFLAGS}"
fi
if [ -z "${CC_BIN}" ] || [ -z "${MAKE_BIN}" ]; then
echo "Failed to resolve compiler or make binary."
exit 1
fi
echo "CC_BIN=${CC_BIN}" >> "${GITHUB_ENV}"
echo "MAKE_BIN=${MAKE_BIN}" >> "${GITHUB_ENV}"
echo "BUILD_CFLAGS=${BUILD_CFLAGS}" >> "${GITHUB_ENV}"
echo "BUILD_VERIFY_CFLAGS=${BUILD_VERIFY_CFLAGS}" >> "${GITHUB_ENV}"
- name: Restore ccache
uses: actions/cache@v4
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ runner.os }}-ccache-${{ hashFiles('Makefile', 'src/**/*.c', 'src/**/*.h', 'tests/**/*.c', 'tests/**/*.h') }}
restore-keys: |
${{ runner.os }}-ccache-
- name: Configure ccache
shell: bash
run: |
ccache --max-size 250M
ccache --zero-stats
- name: Run verify, test, and check
shell: bash
run: |
"${MAKE_BIN}" clean
"${MAKE_BIN}" verify \
CC="ccache ${CC_BIN}" \
CFLAGS="${BUILD_CFLAGS}" \
VERIFY_CFLAGS="${BUILD_VERIFY_CFLAGS}"
"${MAKE_BIN}" test \
CC="ccache ${CC_BIN}" \
CFLAGS="${BUILD_CFLAGS}" \
VERIFY_CFLAGS="${BUILD_VERIFY_CFLAGS}"
"${MAKE_BIN}" check \
CC="ccache ${CC_BIN}" \
CFLAGS="${BUILD_CFLAGS}" \
VERIFY_CFLAGS="${BUILD_VERIFY_CFLAGS}"
- name: Show ccache statistics
if: always()
run: ccache --show-stats
- name: Upload compiled binaries
uses: actions/upload-artifact@v4
with:
name: binaries-${{ runner.os }}
if-no-files-found: error
retention-days: 14
path: |
vuln_buffer_overflow
safe_input_demo
stack_layout_demo
overflow_behavior_demo
control_flow_simulation
demo_runtime_checks
security:
name: Hardened and sanitizer checks
runs-on: ubuntu-latest
needs: lint
timeout-minutes: 20
env:
ASAN_OPTIONS: detect_leaks=1:halt_on_error=1:strict_string_checks=1
UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install security build dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcc make ccache
- name: Restore ccache
uses: actions/cache@v4
with:
path: ${{ env.CCACHE_DIR }}
key: security-ccache-${{ hashFiles('Makefile', 'src/**/*.c', 'src/**/*.h', 'tests/**/*.c', 'tests/**/*.h') }}
restore-keys: |
security-ccache-
- name: Configure ccache
shell: bash
run: |
ccache --max-size 250M
ccache --zero-stats
- name: Run hardened build and test
shell: bash
run: |
make clean
make check \
CC="ccache gcc" \
CFLAGS="${DEFAULT_CFLAGS}" \
VERIFY_CFLAGS="${DEFAULT_VERIFY_CFLAGS}"
- name: Run AddressSanitizer and UBSan checks
shell: bash
run: |
make clean
make check \
CC="ccache gcc" \
CFLAGS="${SANITIZER_CFLAGS}" \
VERIFY_CFLAGS="${SANITIZER_CFLAGS}"
- name: Show ccache statistics
if: always()
run: ccache --show-stats