If stdin is a TTY, but opening it for writing fails, then stdin and
stderr are used as defaults and the TTY doesn't have echo disabled. The
later test to restore echo just checks if stdin is a TTY and not that it
was opened successfully causing a NULL FILE pointer to be fileno(3)'d.
Fixes
da6af9633. This function's logic remains a bit contorted; I went
for the minimal fix.
*p++ = ch;
*p = '\0';
- if (istty) {
+ if (istty && fin != stdin) {
(void)tcsetattr(fileno(fin), TCSANOW, &oterm);
rewind(fout);
(void)fputc('\n', fout);