Skip to content

Commit

Permalink
Enhance debuglib checking
Browse files Browse the repository at this point in the history
Fix #2557.

Signed-off-by: Steven Bellock <sbellock@nvidia.com>
  • Loading branch information
steven-bellock authored and jyao1 committed Feb 9, 2024
1 parent 788239e commit 11a60b3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions os_stub/debuglib/debuglib.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,22 @@ void libspdm_debug_print(size_t error_level, const char *format, ...)
{
char buffer[LIBSPDM_MAX_DEBUG_MESSAGE_LENGTH];
va_list marker;
int status;

if ((error_level & LIBSPDM_DEBUG_LEVEL_CONFIG) == 0) {
return;
}

va_start(marker, format);

vsnprintf(buffer, sizeof(buffer), format, marker);

status = vsnprintf(buffer, sizeof(buffer), format, marker);
va_end(marker);

/* If status is negative then an encoding error has ocurred. */
assert(status >= 0);
/* If status is greater than or equal to the size of the buffer then the buffer is not
* large enough to handle the formatted string. */
assert(status < sizeof(buffer));

printf("%s", buffer);
}
#endif /* LIBSPDM_DEBUG_PRINT_ENABLE */

0 comments on commit 11a60b3

Please sign in to comment.