Skip to content

Commit

Permalink
FAPI: Fix Fapi_Quote errors.
Browse files Browse the repository at this point in the history
* Invalid free was executed when the event list is empty.
* QuoteInfo was not freed in error cases.
* Initialization of certificate was moved to last state
  of the state machine.

Signed-off-by: Juergen Repp <[email protected]>
  • Loading branch information
JuergenReppSIT committed Jan 25, 2024
1 parent 84ead1b commit 867e36d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/tss2-fapi/api/Fapi_Quote.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ Fapi_Quote_Finish(

/* Return the key's certificate if requested. */
if (certificate) {
strdup_check(*certificate, sig_key_object->misc.key.certificate, r, error_cleanup);
strdup_check(command->certificate, sig_key_object->misc.key.certificate, r, error_cleanup);
}

/* If the pcrLog was not requested, the operation is done. */
Expand Down Expand Up @@ -460,6 +460,8 @@ Fapi_Quote_Finish(

if (pcrLog)
*pcrLog = command->pcrLog;
if (certificate)
*certificate = command->certificate;
*signature = command->signature;
*signatureSize = command->signatureSize;
break;
Expand All @@ -474,6 +476,8 @@ Fapi_Quote_Finish(
SAFE_FREE(command->keyPath);
SAFE_FREE(command->pcrList);
if (r) {
SAFE_FREE(command->certificate);
SAFE_FREE(command->quoteInfo);
SAFE_FREE(command->pcrLog);
SAFE_FREE(command->signature);
}
Expand Down
3 changes: 2 additions & 1 deletion src/tss2-fapi/fapi_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ typedef struct {
uint32_t const *hashAlgs;
uint32_t *hashAlgs2;
size_t numHashAlgs;
char const *quoteInfo;
char const *quoteInfo;
char *certificate;
TPM2B_ATTEST *tpm_quoted;
TPMT_SIGNATURE *tpm_signature;
uint8_t *signature;
Expand Down
6 changes: 4 additions & 2 deletions src/tss2-fapi/ifapi_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ ifapi_calculate_pcrs(
}
}
}
if (i_evt == n_events && quote_digest) {
if (n_events > 0 && i_evt == n_events && quote_digest) {
/* Quote digest was not found. */
r = TSS2_FAPI_RC_SIGNATURE_VERIFICATION_FAILED;
}
Expand All @@ -2242,7 +2242,9 @@ ifapi_calculate_pcrs(
error_cleanup:
if (cryptoContext)
ifapi_crypto_hash_abort(&cryptoContext);
ifapi_cleanup_event(&event);
if (n_events > 0) {
ifapi_cleanup_event(&event);
}
return r;
}

Expand Down

0 comments on commit 867e36d

Please sign in to comment.