]> git.proxmox.com Git - swtpm.git/commitdiff
Only allow a single command per TCP connection to be sent
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Fri, 13 Mar 2015 01:45:34 +0000 (21:45 -0400)
committerStefan Berger <stefanb@linux.vnet.ibm.com>
Fri, 13 Mar 2015 01:45:34 +0000 (21:45 -0400)
Only allow a single command per TCP connection to be sent to
the socket TPM. This solves a problem with the test_parameters
testcase where the TPM seems to get stuck in the poll().
However, the testcase still is not entirely error-free.

src/swtpm/swtpm.c

index b919859eca8a8efc02a7346582367e8411a04382..0b72be6e8d6e4d4858875965b5dcb6f9cc514c69 100644 (file)
@@ -367,15 +367,24 @@ static int mainLoop(struct mainLoopParams *mlp)
         while (rc == 0) {
             struct pollfd pollfds = {
                 .fd = connection_fd.fd,
-                .events = POLLIN,
+                .events = POLLIN | POLLHUP,
                 .revents = 0,
             };
 
-            if (poll(&pollfds, 1, -1) < 0) {
+            /*
+             * all these check (seem to) prevent that we get
+             * stuck with a closed connection.
+             */
+            if (poll(&pollfds, 1, -1) < 0 ||
+                (pollfds.revents & POLLHUP) != 0 ||
+                (pollfds.revents & POLLIN) == 0 ) {
                 SWTPM_IO_Disconnect(&connection_fd);
                 break;
             }
 
+            if (!(pollfds.revents & POLLIN))
+                continue;
+
             /* Read the command.  The number of bytes is determined by 'paramSize' in the stream */
             if (rc == 0) {
                 rc = SWTPM_IO_Read(&connection_fd, command, &command_length,
@@ -393,6 +402,11 @@ static int mainLoop(struct mainLoopParams *mlp)
             if (rc == 0) {
                 rc = SWTPM_IO_Write(&connection_fd, rbuffer, rlength);
             }
+            /*
+             * only allow a single command per connection, otherwise
+             * we may get stuck in the poll() above.
+             */
+            break;
         }
         SWTPM_IO_Disconnect(&connection_fd);
         /* clear the response buffer, does not deallocate memory */