From: Todd C. Miller Date: Fri, 15 Jun 2018 19:31:58 +0000 (-0600) Subject: Fix fd leak introduced by SUDO_CONV_PREFER_TTY commit. Coverity CID 186605. X-Git-Tag: SUDO_1_8_24^2~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1385613797aab90d61d3b6406404d0bab74203d7;p=sudo Fix fd leak introduced by SUDO_CONV_PREFER_TTY commit. Coverity CID 186605. --- diff --git a/src/conversation.c b/src/conversation.c index a7b5091bf..969adbec1 100644 --- a/src/conversation.c +++ b/src/conversation.c @@ -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)