45 lines
1.8 KiB
Diff
45 lines
1.8 KiB
Diff
From 66bcb37ac78d8e0f7324f6a7f02dcff3190ec6a3 Mon Sep 17 00:00:00 2001
|
|
From: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
|
|
Date: Sun, 15 Feb 2026 04:39:57 +0900
|
|
Subject: [PATCH 17/30] fix(tpm2_send): validate command_size before computing
|
|
data_size
|
|
|
|
Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
|
|
---
|
|
tools/tpm2_send.c | 16 ++++++++++------
|
|
1 file changed, 10 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/tools/tpm2_send.c b/tools/tpm2_send.c
|
|
index a4da5692..10751f9b 100644
|
|
--- a/tools/tpm2_send.c
|
|
+++ b/tools/tpm2_send.c
|
|
@@ -47,15 +47,19 @@ static int read_command_from_file(FILE *f, tpm2_command_header **c,
|
|
const tpm2_command_header *header = tpm2_command_header_from_bytes(buffer);
|
|
|
|
UINT32 command_size = tpm2_command_header_get_size(header, true);
|
|
- UINT32 data_size = tpm2_command_header_get_size(header, false);
|
|
-
|
|
- if (command_size > TPM2_MAX_SIZE || command_size < data_size) {
|
|
- LOG_ERR("Command buffer %"PRIu32" bytes cannot be smaller then the "
|
|
- "encapsulated data %"PRIu32" bytes, and can not be bigger than"
|
|
- " the maximum buffer size", command_size, data_size);
|
|
+ if (command_size < TPM2_COMMAND_HEADER_SIZE) {
|
|
+ LOG_ERR("Command buffer size %"PRIu32" is smaller than command header "
|
|
+ "size %zu", command_size, TPM2_COMMAND_HEADER_SIZE);
|
|
+ return -1;
|
|
+ }
|
|
+ if (command_size > TPM2_MAX_SIZE) {
|
|
+ LOG_ERR("Command buffer size %"PRIu32" exceeds maximum buffer size %u",
|
|
+ command_size, TPM2_MAX_SIZE);
|
|
return -1;
|
|
}
|
|
|
|
+ UINT32 data_size = tpm2_command_header_get_size(header, false);
|
|
+
|
|
tpm2_command_header *command = (tpm2_command_header *) malloc(command_size);
|
|
if (!command) {
|
|
LOG_ERR("oom");
|
|
--
|
|
2.54.0
|
|
|