Skip to content

Commit

Permalink
Fix message logging bugs
Browse files Browse the repository at this point in the history
Fix DMTF#1842.
Fix DMTF#1843.

Signed-off-by: Steven Bellock <[email protected]>
  • Loading branch information
steven-bellock authored and jyao1 committed Jul 3, 2023
1 parent 714b272 commit 3c87e10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
3 changes: 2 additions & 1 deletion include/library/spdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ libspdm_return_t libspdm_init_context(void *spdm_context);
/**
* Reset an SPDM context.
*
* The size in bytes of the spdm_context can be returned by libspdm_get_context_size.
* Note that message logging is not reset by this function. To reset the message logger call
* libspdm_reset_msg_log.
*
* @param spdm_context A pointer to the SPDM context.
*/
Expand Down
15 changes: 0 additions & 15 deletions library/spdm_common_lib/libspdm_com_context_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -2652,13 +2652,6 @@ libspdm_return_t libspdm_init_context(void *spdm_context)
LIBSPDM_MAX_SESSION_COUNT);
}

/**
* Reset an SPDM context.
*
* The size in bytes of the spdm_context can be returned by libspdm_get_context_size.
*
* @param spdm_context A pointer to the SPDM context.
*/
void libspdm_reset_context(void *spdm_context)
{
libspdm_context_t *context;
Expand Down Expand Up @@ -2697,14 +2690,6 @@ void libspdm_reset_context(void *spdm_context)
context->mut_auth_cert_chain_buffer_size = 0;
context->current_dhe_session_count = 0;
context->current_psk_session_count = 0;

#if LIBSPDM_ENABLE_MSG_LOG
context->msg_log.buffer = NULL;
context->msg_log.max_buffer_size = 0;
context->msg_log.buffer_size = 0;
context->msg_log.mode = 0;
context->msg_log.status = 0;
#endif /* LIBSPDM_ENABLE_MSG_LOG */
}

/**
Expand Down
16 changes: 13 additions & 3 deletions library/spdm_requester_lib/libspdm_req_send_receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ libspdm_return_t libspdm_send_spdm_request(libspdm_context_t *spdm_context,
libspdm_session_info_t *session_info;
libspdm_session_state_t session_state;
libspdm_return_t status;
#if LIBSPDM_ENABLE_MSG_LOG
size_t msg_log_size;
#endif /* LIBSPDM_ENABLE_MSG_LOG */

/* large SPDM message is the SPDM message whose size is greater than the DataTransferSize of the receiving
* SPDM endpoint or greater than the transmit buffer size of the sending SPDM endpoint */
Expand Down Expand Up @@ -598,6 +601,12 @@ libspdm_return_t libspdm_send_spdm_request(libspdm_context_t *spdm_context,
}
}

#if LIBSPDM_ENABLE_MSG_LOG
/* First save the size of the message log buffer. If there is an error it will be reverted. */
msg_log_size = libspdm_get_msg_log_size(spdm_context);
libspdm_append_msg_log(spdm_context, request, request_size);
#endif /* LIBSPDM_ENABLE_MSG_LOG */

/* large SPDM message is the SPDM message whose size is greater than the DataTransferSize of the receiving
* SPDM endpoint or greater than the transmit buffer size of the sending SPDM endpoint */
if (((const spdm_message_header_t*) request)->request_response_code != SPDM_GET_VERSION
Expand Down Expand Up @@ -640,10 +649,11 @@ libspdm_return_t libspdm_send_spdm_request(libspdm_context_t *spdm_context,
}

#if LIBSPDM_ENABLE_MSG_LOG
if (status == LIBSPDM_STATUS_SUCCESS) {
libspdm_append_msg_log(spdm_context, request, request_size);
/* If there is an error in sending the request then revert the request in the message log. */
if (LIBSPDM_STATUS_IS_ERROR(status)) {
spdm_context->msg_log.buffer_size = msg_log_size;
}
#endif
#endif /* LIBSPDM_ENABLE_MSG_LOG */

return status;
}
Expand Down

0 comments on commit 3c87e10

Please sign in to comment.