Skip to content

Commit 5c4484b

Browse files
committed
add scan build github action
1 parent 1eda4bc commit 5c4484b

File tree

14 files changed

+200
-12
lines changed

14 files changed

+200
-12
lines changed

.github/workflows/static-analysis.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ jobs:
6363
echo "❌ Static analysis failed - errors or warnings were found"
6464
exit 1
6565
66+
scan-build:
67+
runs-on: ubuntu-latest
68+
69+
steps:
70+
- name: Checkout wolfHSM
71+
uses: actions/checkout@v4
72+
with:
73+
path: wolfHSM
74+
75+
- name: Checkout wolfssl
76+
uses: actions/checkout@v4
77+
with:
78+
repository: wolfssl/wolfssl
79+
path: wolfssl
80+
81+
- name: Install dependencies
82+
run: |
83+
sudo apt-get update
84+
sudo apt-get install -y clang build-essential clang-tools
85+
86+
- name: Run scan-build
87+
id: scan-build
88+
run:
89+
cd wolfHSM && make scan
90+
91+
- name: Fail if scan-build issues found
92+
if: steps.scan-build.outcome == 'failure'
93+
run: |
94+
echo "❌ scan-build analysis failed - errors or warnings were found"
95+
exit 1
96+
6697
clang-tidy:
6798
runs-on: ubuntu-latest
6899

@@ -106,7 +137,6 @@ jobs:
106137
echo ""
107138
# Show first 50 issues to avoid overwhelming output
108139
head -50 tools/static-analysis/reports/clang_tidy_summary.txt
109-
110140
TOTAL_ISSUES=$((ERROR_COUNT + WARNING_COUNT))
111141
if [ "$TOTAL_ISSUES" -gt 50 ]; then
112142
echo ""

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ tools:
1515
examples:
1616
make -C examples
1717

18+
SCAN_DIR = ./scan_out
19+
20+
scan_result_check:
21+
@num=$$(grep -h -o '^[0-9]\+ warnings\? generated' ./$(SCAN_DIR)/*.log | grep -o '^[0-9]\+' | awk '{s+=$$1} END {print s}');\
22+
if [ -z "$$num" ]; then \
23+
echo "no warnings found";\
24+
exit 0; \
25+
fi; \
26+
if [ $$num -ne 0 ]; then \
27+
echo "scan-build found $$num warnings";\
28+
for f in $(SCAN_DIR)/*.log; do \
29+
echo "---- $$f ----"; \
30+
cat $$f; \
31+
echo ""; \
32+
done; \
33+
exit 1; \
34+
fi;
35+
36+
scan:
37+
@echo "Running scan-build static analysis"
38+
@rm -rf $(SCAN_DIR)
39+
@mkdir -p $(SCAN_DIR)
40+
@make clean
41+
-@make SCAN=1 -C test scan
42+
-@make SCAN=1 -C benchmark scan
43+
-@make NOCRYPTO=1 SCAN=1 -C tools/whnvmtool scan
44+
-@make NOCRYPTO=1 SCAN=1 -C examples
45+
@$(MAKE) scan_result_check
46+
1847
clean:
1948
make -C test clean
2049
make -C benchmark clean

benchmark/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ ifeq ($(NOCRYPTO),1)
103103
DEF += -DWOLFHSM_CFG_NO_CRYPTO
104104
endif
105105

106+
ifeq ($(SCAN),1)
107+
SCAN_LOG = scan_benchmark.log
108+
# Default target
109+
.DEFAULT_GOAL := scan
110+
endif
111+
106112
# Support a DMA-capable build
107113
ifeq ($(DMA),1)
108114
DEF += -DWOLFHSM_CFG_DMA
@@ -161,6 +167,13 @@ build_static: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).a
161167
@echo ""
162168
$(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(BIN).a
163169

170+
analyze: $(OBJS_ASM) $(OBJS_C)
171+
172+
scan:$(BUILD_DIR)
173+
@echo "Running scan-build static analysis"
174+
@mkdir -p $(WOLFHSM_DIR)/scan_out/
175+
@scan-build --status-bugs $(MAKE) analyze 2> $(WOLFHSM_DIR)/scan_out/$(SCAN_LOG)
176+
164177
$(BUILD_DIR):
165178
$(CMD_ECHO) mkdir -p $(BUILD_DIR)
166179

examples/demo/client/wh_demo_client_crypto.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
#include "wh_demo_client_crypto.h"
4242

43+
#ifndef WOLFHSM_CFG_NO_CRYPTO
44+
4345
#if !defined(NO_RSA)
4446

4547
/*
@@ -1357,3 +1359,4 @@ int wh_DemoClient_CryptoCmacOneshotImport(whClientContext* clientContext)
13571359
return ret;
13581360
}
13591361
#endif /* WOLFSSL_CMAC && !NO_AES */
1362+
#endif /* WOLFHSM_CFG_NO_CRYPTO */

examples/demo/client/wh_demo_client_keystore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int wh_DemoClient_KeystoreCommitKey(whClientContext* clientContext)
121121
return WH_ERROR_OK;
122122
}
123123

124-
#ifndef NO_AES
124+
#if !defined(NO_AES) && !defined(WOLFHSM_CFG_NO_CRYPTO)
125125
int wh_DemoClient_KeystoreAes(whClientContext* clientContext)
126126
{
127127
int ret;

examples/demo/client/wh_demo_client_secboot.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static int _showNvm(whClientContext* clientContext)
9898

9999
static int _provisionMakeCommitKey(whClientContext* clientContext)
100100
{
101+
#ifndef WOLFHSM_CFG_NO_CRYPTO
101102
int ret;
102103

103104
/* Use the default ECC curve for 32 byte key, likely P256r1 */
@@ -112,10 +113,15 @@ static int _provisionMakeCommitKey(whClientContext* clientContext)
112113
ret = wh_Client_KeyCommit(clientContext, prov_keyId);
113114
}
114115
return ret;
116+
#else
117+
(void)clientContext;
118+
return WH_ERROR_NOTIMPL;
119+
#endif
115120
}
116121

117122
static int _sha256File(const char* file_to_measure, uint8_t* hash)
118123
{
124+
#ifndef WOLFHSM_CFG_NO_CRYPTO
119125
int ret = 0;
120126
int fd = open(file_to_measure, O_RDONLY);
121127
if (fd >= 0) {
@@ -149,11 +155,17 @@ static int _sha256File(const char* file_to_measure, uint8_t* hash)
149155
ret = WH_ERROR_BADARGS;
150156
}
151157
return ret;
158+
#else
159+
(void)file_to_measure;
160+
(void)hash;
161+
return WH_ERROR_NOTIMPL;
162+
#endif
152163
}
153164

154165
static int _signHash(const uint8_t* hash, size_t hash_len, uint8_t* sig,
155166
uint16_t* sig_len)
156167
{
168+
#ifndef WOLFHSM_CFG_NO_CRYPTO
157169
ecc_key key[1];
158170
int ret = wc_ecc_init_ex(key, NULL, WH_DEV_ID);
159171
if (ret == 0) {
@@ -169,11 +181,19 @@ static int _signHash(const uint8_t* hash, size_t hash_len, uint8_t* sig,
169181
(void)wc_ecc_free(key);
170182
}
171183
return ret;
184+
#else
185+
(void)hash;
186+
(void)hash_len;
187+
(void)sig;
188+
(void)sig_len;
189+
return WH_ERROR_NOTIMPL;
190+
#endif
172191
}
173192

174193
static int _verifyHash(const uint8_t* hash, size_t hash_len, const uint8_t* sig,
175194
uint16_t sig_len, int32_t* rc)
176195
{
196+
#ifndef WOLFHSM_CFG_NO_CRYPTO
177197
ecc_key key[1];
178198
int ret = wc_ecc_init_ex(key, NULL, WH_DEV_ID);
179199
if (ret == 0) {
@@ -189,6 +209,14 @@ static int _verifyHash(const uint8_t* hash, size_t hash_len, const uint8_t* sig,
189209
(void)wc_ecc_free(key);
190210
}
191211
return ret;
212+
#else
213+
(void)hash;
214+
(void)hash_len;
215+
(void)sig;
216+
(void)sig_len;
217+
(void)rc;
218+
return WH_ERROR_NOTIMPL;
219+
#endif
192220
}
193221

194222
int wh_DemoClient_SecBoot_Provision(whClientContext* clientContext)

examples/posix/wh_posix_client/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ endif
7979
# Assembly source files
8080
SRC_ASM +=
8181

82+
ifneq ($(NOCRYPTO),1)
8283
# wolfCrypt source files
8384
SRC_C += $(wildcard $(WOLFSSL_DIR)/wolfcrypt/src/*.c)
8485

@@ -102,6 +103,16 @@ endif
102103
SRC_C += $(wildcard $(WOLFSSL_DIR)/wolfcrypt/test/*.c)
103104
SRC_C += $(wildcard $(WOLFSSL_DIR)/wolfcrypt/benchmark/*.c)
104105

106+
else
107+
DEF += -DWOLFHSM_CFG_NO_CRYPTO
108+
endif
109+
110+
ifeq ($(SCAN),1)
111+
SCAN_LOG = scan_posix_client.log
112+
# Default target
113+
.DEFAULT_GOAL := scan
114+
endif
115+
105116
# wolfHSM source files
106117
SRC_C += $(wildcard $(WOLFHSM_DIR)/src/*.c)
107118

@@ -163,6 +174,13 @@ $(BUILD_DIR)/$(BIN).a: $(OBJS_ASM) $(OBJS_C)
163174
@echo "Building static library: $(notdir $@)"
164175
$(CMD_ECHO) $(AR) -r $@ $^
165176

177+
analyze: $(OBJS_ASM) $(OBJS_C)
178+
179+
scan:$(BUILD_DIR)
180+
@echo "Running scan-build static analysis"
181+
@mkdir -p $(WOLFHSM_DIR)/scan_out/
182+
@scan-build --status-bugs $(MAKE) analyze 2> $(WOLFHSM_DIR)/scan_out/$(SCAN_LOG)
183+
166184
clean:
167185
@echo "Cleaning build files"
168186
@rm -f \
@@ -173,4 +191,3 @@ clean:
173191
$(BUILD_DIR)/*.a \
174192
$(BUILD_DIR)/*.sym \
175193
$(BUILD_DIR)/*.disasm
176-

examples/posix/wh_posix_client/wh_posix_client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int wh_ClientTask(void* cf, const char* type, int test)
124124
break;
125125
}
126126
}
127-
127+
#if defined(DWOLFHSM_CFG_NO_CRYPTO)
128128
/* Context 1: Client Local Crypto */
129129
WC_RNG rng[1];
130130
uint8_t buffer[128] = {0};
@@ -139,7 +139,7 @@ static int wh_ClientTask(void* cf, const char* type, int test)
139139
wc_RNG_GenerateBlock(rng, buffer, sizeof(buffer));
140140
wc_FreeRng(rng);
141141
wh_Utils_Hexdump("Context 2: Client Remote RNG:\n", buffer, sizeof(buffer));
142-
142+
#endif
143143

144144
(void)wh_Client_CommClose(client);
145145
(void)wh_Client_Cleanup(client);

examples/posix/wh_posix_server/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,19 @@ endif
8080
SRC_ASM +=
8181

8282
# wolfCrypt source files
83+
ifneq ($(NOCRYPTO),1)
8384
SRC_C += $(wildcard $(WOLFSSL_DIR)/wolfcrypt/src/*.c)
8485
# wolfSSL source files
8586
SRC_C += $(wildcard $(WOLFSSL_DIR)/src/*.c)
87+
else
88+
DEF += -DWOLFHSM_CFG_NO_CRYPTO
89+
endif
90+
91+
ifeq ($(SCAN),1)
92+
SCAN_LOG = scan_posix_server.log
93+
# Default target
94+
.DEFAULT_GOAL := scan
95+
endif
8696

8797
# wolfHSM source files
8898
SRC_C += $(wildcard $(WOLFHSM_DIR)/src/*.c)
@@ -118,6 +128,13 @@ build_static: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).a
118128
@echo ""
119129
$(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(BIN).a
120130

131+
analyze: $(OBJS_ASM) $(OBJS_C)
132+
133+
scan:$(BUILD_DIR)
134+
@echo "Running scan-build static analysis"
135+
@mkdir -p $(WOLFHSM_DIR)/scan_out/
136+
@scan-build --status-bugs $(MAKE) analyze 2> $(WOLFHSM_DIR)/scan_out/$(SCAN_LOG)
137+
121138
$(BUILD_DIR):
122139
$(CMD_ECHO) mkdir -p $(BUILD_DIR)
123140

examples/posix/wh_posix_server/wh_posix_server.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ static int wh_ServerTask(void* cf, const char* keyFilePath, int keyId,
3535
int clientId);
3636

3737
static void _sleepMs(long milliseconds);
38+
#if !defined(WOLFHSM_CFG_NO_CRYPTO)
3839
static int _hardwareCryptoCb(int devId, struct wc_CryptoInfo* info, void* ctx);
39-
40+
#endif
4041
static void _sleepMs(long milliseconds)
4142
{
4243
struct timespec req;
@@ -217,7 +218,7 @@ static int wh_ServerTask(void* cf, const char* keyFilePath, int keyId,
217218
}
218219
return ret;
219220
}
220-
221+
#if !defined(WOLFHSM_CFG_NO_CRYPTO)
221222
static int _hardwareCryptoCb(int devId, struct wc_CryptoInfo* info, void* ctx)
222223
{
223224
(void)devId;
@@ -254,7 +255,7 @@ static int _hardwareCryptoCb(int devId, struct wc_CryptoInfo* info, void* ctx)
254255
}
255256
return ret;
256257
}
257-
258+
#endif
258259
static void Usage(const char* exeName)
259260
{
260261
printf("Usage: %s --key <key_file_path> --id <key_id> --client <client_id> "
@@ -342,7 +343,7 @@ int main(int argc, char** argv)
342343
printf("Failed to initialize NVM: %d\n", rc);
343344
return rc;
344345
}
345-
346+
#if !defined(WOLFHSM_CFG_NO_CRYPTO)
346347
/* Crypto context */
347348
whServerCryptoContext crypto[1] = {{
348349
.devId = INVALID_DEVID,
@@ -405,6 +406,11 @@ int main(int argc, char** argv)
405406
printf("Failed to wolfCrypt_Cleanup: %d\n", rc);
406407
return rc;
407408
}
408-
409+
#else
410+
(void)keyFilePath;
411+
(void)keyId;
412+
(void)clientId;
413+
(void)wh_ServerTask;
414+
#endif
409415
return rc;
410416
}

0 commit comments

Comments
 (0)