diff options
author | Sergii Dmytruk <sergii.dmytruk@3mdeb.com> | 2022-11-16 20:52:47 +0200 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2023-01-11 16:03:49 +0000 |
commit | c807d55798f000c8a8eb0141302a66915f10d0a1 (patch) | |
tree | 283ff8a8e78c78a090aae1c94b88cae7d18736bd /src/security | |
parent | 26203e729251816f8a98814112730daf61492a3e (diff) |
security/tpm/tspi/log.c: fix strncpy() usage
Change-Id: Ib24129829bef3764a8ba1e2c0d92bc42c5cfbc8d
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/69708
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/security')
-rw-r--r-- | src/security/tpm/tspi/log.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/security/tpm/tspi/log.c b/src/security/tpm/tspi/log.c index 96c3087f95..e33cacb87a 100644 --- a/src/security/tpm/tspi/log.c +++ b/src/security/tpm/tspi/log.c @@ -77,6 +77,8 @@ void tpm_log_add_table_entry(const char *name, const uint32_t pcr, struct tpm_cb_log_entry *tce = &tclt->entries[tclt->num_entries++]; strncpy(tce->name, name, TPM_CB_LOG_PCR_HASH_NAME - 1); + tce->name[TPM_CB_LOG_PCR_HASH_NAME - 1] = '\0'; + tce->pcr = pcr; if (digest_len > TPM_CB_LOG_DIGEST_MAX_LENGTH) { @@ -143,7 +145,10 @@ void tpm_log_copy_entries(const void *from, void *to) for (i = 0; i < from_log->num_entries; i++) { struct tpm_cb_log_entry *tce = &to_log->entries[to_log->num_entries++]; + strncpy(tce->name, from_log->entries[i].name, TPM_CB_LOG_PCR_HASH_NAME - 1); + tce->name[TPM_CB_LOG_PCR_HASH_NAME - 1] = '\0'; + tce->pcr = from_log->entries[i].pcr; if (from_log->entries[i].digest_length > TPM_CB_LOG_DIGEST_MAX_LENGTH) { @@ -153,6 +158,8 @@ void tpm_log_copy_entries(const void *from, void *to) strncpy(tce->digest_type, from_log->entries[i].digest_type, TPM_CB_LOG_PCR_HASH_LEN - 1); + tce->digest_type[TPM_CB_LOG_PCR_HASH_LEN - 1] = '\0'; + tce->digest_length = MIN(from_log->entries[i].digest_length, TPM_CB_LOG_DIGEST_MAX_LENGTH); memcpy(tce->digest, from_log->entries[i].digest, tce->digest_length); |