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 state machine.

Signed-off-by: Juergen Repp <[email protected]>
  • Loading branch information
JuergenReppSIT committed Jan 25, 2024
1 parent 84ead1b commit 6b0b1dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/tss2-fapi/api/Fapi_Quote.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,6 @@ Fapi_Quote_Finish(
quoteInfo);
goto_if_error(r, "Create compute quote info.", error_cleanup);

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

/* If the pcrLog was not requested, the operation is done. */
if (!pcrLog) {
context->state = PCR_QUOTE_CLEANUP;
Expand Down Expand Up @@ -458,6 +453,11 @@ Fapi_Quote_Finish(
r = ifapi_cleanup_session(context);
try_again_or_error_goto(r, "Cleanup", error_cleanup);

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

if (pcrLog)
*pcrLog = command->pcrLog;
*signature = command->signature;
Expand All @@ -474,6 +474,7 @@ Fapi_Quote_Finish(
SAFE_FREE(command->keyPath);
SAFE_FREE(command->pcrList);
if (r) {
SAFE_FREE(command->quoteInfo);
SAFE_FREE(command->pcrLog);
SAFE_FREE(command->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 6b0b1dd

Please sign in to comment.