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.
pull/880/head
Andrew Hutchings 2026-02-23 10:23:26 +00:00
parent 99319bf773
commit 82b9f1138d
1 changed files with 8 additions and 6 deletions

View File

@ -405,11 +405,12 @@ void wolfSSH_SetTpmDev(WOLFSSH* ssh, WOLFTPM2_DEV* dev)
{
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetTpmDev()");
if (ssh && ssh->ctx)
if (ssh && ssh->ctx) {
ssh->ctx->tpmDev = dev;
if (ssh->ctx->tpmDev == NULL) {
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmDev: Set tpm dev failed");
if (ssh->ctx->tpmDev == NULL) {
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmDev: Set tpm dev failed");
}
}
}
@ -418,11 +419,12 @@ void wolfSSH_SetTpmKey(WOLFSSH* ssh, WOLFTPM2_KEY* key)
{
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SetTpmKey()");
if (ssh && ssh->ctx)
if (ssh && ssh->ctx) {
ssh->ctx->tpmKey = key;
if (ssh->ctx->tpmDev == NULL) {
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmKey: Set tpm key failed");
if (ssh->ctx->tpmKey == NULL) {
WLOG(WS_LOG_DEBUG, "wolfSSH_SetTpmKey: Set tpm key failed");
}
}
}