Check write() from TTY prompt.

pull/2/head
Christopher Wellons 2017-03-03 20:51:42 -05:00
parent bb46184a49
commit 1716985257
1 changed files with 4 additions and 2 deletions

View File

@ -92,7 +92,8 @@ get_passphrase(char *buf, size_t len, char *prompt)
char newline = '\n'; char newline = '\n';
size_t i = 0; size_t i = 0;
struct termios old, new; struct termios old, new;
write(tty, prompt, strlen(prompt)); if (write(tty, prompt, strlen(prompt)) == -1)
fatal("error asking for passphrase");
tcgetattr(tty, &old); tcgetattr(tty, &old);
new = old; new = old;
new.c_lflag &= ~ECHO; new.c_lflag &= ~ECHO;
@ -105,7 +106,8 @@ get_passphrase(char *buf, size_t len, char *prompt)
} }
buf[i] = 0; buf[i] = 0;
tcsetattr(tty, TCSANOW, &old); tcsetattr(tty, TCSANOW, &old);
write(tty, &newline, 1); if (write(tty, &newline, 1) == -1)
fatal("error asking for passphrase");
close(tty); close(tty);
if (errno) if (errno)
fatal("could not read passphrase from /dev/tty"); fatal("could not read passphrase from /dev/tty");