]> granicus.if.org Git - sudo/commitdiff
Fix fd leak introduced by SUDO_CONV_PREFER_TTY commit. Coverity CID 186605.
authorTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 15 Jun 2018 19:31:58 +0000 (13:31 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 15 Jun 2018 19:31:58 +0000 (13:31 -0600)
src/conversation.c

index a7b5091bff3e63f69dd16b0af2629259258c08e2..969adbec1ae38282e2435a2ec344a6d5164e43ba 100644 (file)
@@ -87,9 +87,11 @@ sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
                    if (ISSET(msg->msg_type, SUDO_CONV_PREFER_TTY)) {
                        /* Try writing to /dev/tty first. */
                        if ((fd = open(_PATH_TTY, O_WRONLY)) != -1) {
-                           if (write(fd, msg->msg, strlen(msg->msg)) != -1)
-                               break;
+                           ssize_t nwritten =
+                               write(fd, msg->msg, strlen(msg->msg));
                            close(fd);
+                           if (nwritten != -1)
+                               break;
                        }
                    }
                    if (fputs(msg->msg, fp) == EOF)