Skip to content

Commit 4833ac0

Browse files
committed
Avoid passing sudo_term_is_raw() -1 for the fd.
Coverity CID 330472 Coverity CID 330468
1 parent 3b891c1 commit 4833ac0

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

plugins/sudoers/sudoreplay.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ setup_terminal(struct eventlog *evlog, bool interactive, bool resize)
629629
/* Open fd for /dev/tty and set to raw mode. */
630630
if (interactive) {
631631
ttyfd = open(_PATH_TTY, O_RDWR);
632+
if (ttyfd == -1)
633+
sudo_fatal("%s", U_("unable to set tty to raw mode"));
634+
if (ttyfd == -1)
632635
while (!sudo_term_raw(ttyfd, SUDO_TERM_ISIG)) {
633636
if (errno != EINTR)
634637
sudo_fatal("%s", U_("unable to set tty to raw mode"));

src/conversation.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
9797
if (ISSET(msg->msg_type, SUDO_CONV_PREFER_TTY) &&
9898
!ISSET(flags, TGP_STDIN)) {
9999
ttyfd = open(_PATH_TTY, O_WRONLY);
100-
raw_tty = sudo_term_is_raw(ttyfd);
100+
if (ttyfd != -1)
101+
raw_tty = sudo_term_is_raw(ttyfd);
101102
} else {
102103
raw_tty = sudo_term_is_raw(fileno(fp));
103104
}

0 commit comments

Comments
 (0)