Skip to content

Commit ca166b0

Browse files
committed
Futher peer review feedback
1 parent 0047cce commit ca166b0

13 files changed

Lines changed: 265 additions & 100 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ if(WOLFTPM_FWTPM)
554554
${CMAKE_CURRENT_SOURCE_DIR}
555555
${CMAKE_CURRENT_BINARY_DIR}
556556
)
557+
target_compile_options(fwtpm_fuzz PRIVATE "-fsanitize=fuzzer-no-link")
557558
target_link_options(fwtpm_fuzz PRIVATE "-fsanitize=fuzzer")
558559
endif()
559560

src/fwtpm/fwtpm.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
int FWTPM_Init(FWTPM_CTX* ctx)
3939
{
4040
int rc;
41+
int rngInit = 0;
4142
FWTPM_NV_HAL savedNvHal;
4243
struct FWTPM_CLOCK_HAL_S savedClockHal;
4344
#ifdef WOLFTPM_FWTPM_TIS
@@ -84,6 +85,9 @@ int FWTPM_Init(FWTPM_CTX* ctx)
8485
rc = wolfCrypt_Init();
8586
if (rc == 0) {
8687
rc = wc_InitRng(&ctx->rng);
88+
if (rc == 0) {
89+
rngInit = 1;
90+
}
8791
}
8892

8993
/* Generate per-boot context protection key (volatile only) for
@@ -120,7 +124,9 @@ int FWTPM_Init(FWTPM_CTX* ctx)
120124
#endif
121125

122126
if (rc != 0) {
123-
wc_FreeRng(&ctx->rng);
127+
if (rngInit) {
128+
wc_FreeRng(&ctx->rng);
129+
}
124130
wolfCrypt_Cleanup();
125131
}
126132

0 commit comments

Comments
 (0)