Skip to content

Commit d81ed02

Browse files
pqcfoxppannuto
authored andcommitted
tutorial: root_of_trust: tighten up IPC screen logging routines using strlcpy
Co-authored-by: Pat Pannuto <[email protected]>
1 parent 43ed0de commit d81ed02

File tree

1 file changed

+3
-6
lines changed
  • examples/tutorials/root_of_trust/questionable_service_milestone_one

1 file changed

+3
-6
lines changed

examples/tutorials/root_of_trust/questionable_service_milestone_one/main.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <stdio.h>
88
#include <stdlib.h>
9+
#include <string.h>
910

1011
#include <libtock/kernel/ipc.h>
1112
#include <libtock/tock.h>
@@ -62,12 +63,8 @@ static int setup_logging() {
6263
static int log_to_screen(const char* message) {
6364
returncode_t ret;
6465

65-
// Copy up to the log buffer's size of the message, with room for a null byte.
66-
uint16_t len = strnlen(message, sizeof(log_buf) - 1);
67-
memcpy(log_buf, message, len);
68-
69-
// Add the null byte.
70-
log_buf[len] = '\0';
66+
// Load the log buffer with our message
67+
strlcpy(log_buf, message, LOG_WIDTH);
7168

7269
// Start the logging process.
7370
ret = ipc_notify_service(screen_service);

0 commit comments

Comments
 (0)