From 1385613797aab90d61d3b6406404d0bab74203d7 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 15 Jun 2018 13:31:58 -0600 Subject: [PATCH] Fix fd leak introduced by SUDO_CONV_PREFER_TTY commit. Coverity CID 186605. --- src/conversation.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) -- 2.40.0