Skip to content

Commit

Permalink
swtpm: Print message in case error response is too long
Browse files Browse the repository at this point in the history
All error messages must only be 4 bytes long. Print an error message if
this is not the case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Oct 11, 2024
1 parent 3a0ff17 commit 8d4b247
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/swtpm/ctrlchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8d4b247

Please sign in to comment.