Skip to content

Commit 11a60b3

Browse files
steven-bellockjyao1
authored andcommitted
Enhance debuglib checking
Fix #2557. Signed-off-by: Steven Bellock <[email protected]>
1 parent 788239e commit 11a60b3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

os_stub/debuglib/debuglib.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,22 @@ void libspdm_debug_print(size_t error_level, const char *format, ...)
6262
{
6363
char buffer[LIBSPDM_MAX_DEBUG_MESSAGE_LENGTH];
6464
va_list marker;
65+
int status;
6566

6667
if ((error_level & LIBSPDM_DEBUG_LEVEL_CONFIG) == 0) {
6768
return;
6869
}
6970

7071
va_start(marker, format);
71-
72-
vsnprintf(buffer, sizeof(buffer), format, marker);
73-
72+
status = vsnprintf(buffer, sizeof(buffer), format, marker);
7473
va_end(marker);
7574

75+
/* If status is negative then an encoding error has ocurred. */
76+
assert(status >= 0);
77+
/* If status is greater than or equal to the size of the buffer then the buffer is not
78+
* large enough to handle the formatted string. */
79+
assert(status < sizeof(buffer));
80+
7681
printf("%s", buffer);
7782
}
7883
#endif /* LIBSPDM_DEBUG_PRINT_ENABLE */

0 commit comments

Comments
 (0)