]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm: check for invalid file descriptor (< 0)
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Fri, 8 Dec 2017 14:43:07 +0000 (09:43 -0500)
committerStefan Berger <stefanb@linux.vnet.ibm.com>
Fri, 8 Dec 2017 14:44:17 +0000 (09:44 -0500)
Check for an invalid file descriptor in SWTPM_IO_Read before accessing
it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
src/swtpm/swtpm_io.c

index 16cbc887edee6a2ae9d19723b95cd19f245f657e..8fe5da12855a9f74ca2f0f5e944ef8b9dba03d7f 100644 (file)
@@ -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);