Skip to content

Commit 82b9f11

Browse files
committed
Fix NULL pointer dereference in wolfSSH_SetTpmDev/SetTpmKey
Move the NULL validation checks inside the existing NULL guards for ssh and ssh->ctx. Previously, the check accessed ssh->ctx outside the guard, causing a NULL dereference when ssh or ssh->ctx was NULL. Also fix wolfSSH_SetTpmKey to check tpmKey instead of tpmDev.
1 parent 99319bf commit 82b9f11

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/ssh.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,12 @@ void wolfSSH_SetTpmDev(WOLFSSH* ssh, WOLFTPM2_DEV* dev)
405405
{
406406
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetTpmDev()");
407407

408-
if (ssh && ssh->ctx)
408+
if (ssh && ssh->ctx) {
409409
ssh->ctx->tpmDev = dev;
410410

411-
if (ssh->ctx->tpmDev == NULL) {
412-
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmDev: Set tpm dev failed");
411+
if (ssh->ctx->tpmDev == NULL) {
412+
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmDev: Set tpm dev failed");
413+
}
413414
}
414415
}
415416

@@ -418,11 +419,12 @@ void wolfSSH_SetTpmKey(WOLFSSH* ssh, WOLFTPM2_KEY* key)
418419
{
419420
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetTpmKey()");
420421

421-
if (ssh && ssh->ctx)
422+
if (ssh && ssh->ctx) {
422423
ssh->ctx->tpmKey = key;
423424

424-
if (ssh->ctx->tpmDev == NULL) {
425-
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmKey: Set tpm key failed");
425+
if (ssh->ctx->tpmKey == NULL) {
426+
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmKey: Set tpm key failed");
427+
}
426428
}
427429
}
428430

0 commit comments

Comments
 (0)