From 8d4b247e3da96708a78f790c10f1d4cdbad51e79 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 11 Oct 2024 15:12:15 -0400 Subject: [PATCH] swtpm: Print message in case error response is too long All error messages must only be 4 bytes long. Print an error message if this is not the case. Signed-off-by: Stefan Berger --- src/swtpm/ctrlchannel.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/swtpm/ctrlchannel.c b/src/swtpm/ctrlchannel.c index 0beb0ccbf..2b9ab24c5 100644 --- a/src/swtpm/ctrlchannel.c +++ b/src/swtpm/ctrlchannel.c @@ -919,6 +919,13 @@ int ctrlchannel_process_fd(int fd, send_resp: SWTPM_PrintAll(" Ctrl Rsp:", " ", output.body, min(out_len, 1024)); + /* all error responses must only be 4 bytes long */ + if (*res_p != htobe32(TPM_SUCCESS) && out_len != 4) { + logprintf(STDERR_FILENO, "Error: Response too long for cmd=0x%x : %u\n", + be32toh(input.cmd), out_len); + out_len = sizeof(ptm_res); + } + n = write_full(fd, output.body, out_len); if (n < 0) { logprintf(STDERR_FILENO,