tpm2-tools/0016-fix-tpm2_util-fix-buffer-overflow-in-string-validati.patch
Štěpán Horáček 9983900131 Backport upstream fixes
Resolves: RHEL-164795

Signed-off-by: Štěpán Horáček <shoracek@redhat.com>
2026-05-30 03:05:41 +02:00

46 lines
1.5 KiB
Diff

From 11874a7231fb8a6dae77f63aaec62fd733a3ef53 Mon Sep 17 00:00:00 2001
From: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
Date: Sun, 1 Mar 2026 02:47:49 +0900
Subject: [PATCH 16/20] fix(tpm2_util): fix buffer overflow in string
validation checks
Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
---
lib/tpm2_util.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/lib/tpm2_util.c b/lib/tpm2_util.c
index a5facec7..e1f4ff91 100644
--- a/lib/tpm2_util.c
+++ b/lib/tpm2_util.c
@@ -1017,22 +1017,20 @@ bool tpm2_safe_read_from_stdin(int length, char *data) {
bool tpm2_pem_encoded_key_to_fingerprint(const char *pem_encoded_key,
char *fingerprint) {
- bool is_pemkey_len_valid = strlen(pem_encoded_key) > 1024 ? false : true;
- if (!is_pemkey_len_valid) {
+ if (strlen(pem_encoded_key) >= 1024) {
return false;
}
char str[1024] = "";
- strcpy(str, pem_encoded_key);
+ strncpy(str, pem_encoded_key, 1023);
+ str[1023] = '\0';
/* walk through other tokens */
char base64[1024] = "";
char *token = strtok(str, "\n");
while ( token != NULL ) {
if (!strstr(token, "-----")) {
- bool is_base64_overrun = (strlen(base64) + strlen(token)) > 1024 ?
- true : false;
- if (is_base64_overrun) {
+ if ((strlen(base64) + strlen(token)) >= 1024) {
return false;
}
strcat(base64, token);
--
2.54.0