From: Stefan Berger Date: Fri, 8 Dec 2017 14:43:07 +0000 (-0500) Subject: swtpm: check for invalid file descriptor (< 0) X-Git-Tag: v0.7.0-rc1~857 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=7306ee278a8a3de908535eb5e023e245d48478d8;p=swtpm.git swtpm: check for invalid file descriptor (< 0) Check for an invalid file descriptor in SWTPM_IO_Read before accessing it. Signed-off-by: Stefan Berger --- diff --git a/src/swtpm/swtpm_io.c b/src/swtpm/swtpm_io.c index 16cbc88..8fe5da1 100644 --- a/src/swtpm/swtpm_io.c +++ b/src/swtpm/swtpm_io.c @@ -107,6 +107,13 @@ TPM_RESULT SWTPM_IO_Read(TPM_CONNECTION_FD *connection_fd, /* read/write file uint32_t paramSize; /* from command stream */ ssize_t n; + if (rc == 0) { + if (connection_fd->fd < 0) { + TPM_DEBUG("SWTPM_IO_Read: Passed file descriptor is invalid\n"); + rc = TPM_IOERROR; + } + } + /* check that the buffer can at least fit the command through the paramSize */ if (rc == 0) { headerSize = sizeof(TPM_TAG) + sizeof(uint32_t);