Skip to content

Commit

Permalink
Auth file: Ensure 0-termination
Browse files Browse the repository at this point in the history
When reading auths from a file, make sure they are 0-terminated.

Signed-off-by: Andreas Fuchs <[email protected]>
  • Loading branch information
AndreasFuchsTPM committed Jan 31, 2024
1 parent 8d24dfa commit 756da45
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/tpm2_auth_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ static tool_rc get_auth_for_file_param(const char* password, TPM2B_AUTH *auth) {
const char* path = password;
size_t size = (sizeof(auth->buffer) * 2) + HEX_PREFIX_LEN + 2;
bool is_a_tty = isatty(STDIN_FILENO);
UINT8 *buffer = calloc(1, size);

/* Allocating one extra byte for \0 termination safety */
UINT8 *buffer = calloc(1, size + 1);
if (!buffer) {
LOG_ERR("oom");
return tool_rc_general_error;
}
buffer[size] = '\0';

if (path) {
path = strcmp("-", path) ? path : NULL;
Expand Down

0 comments on commit 756da45

Please sign in to comment.