Skip to content

Commit

Permalink
terminal: seek when switching between reading and writing
Browse files Browse the repository at this point in the history
When a stdio stream is opened in update mode (e.g., "w+"),
the C standard forbids switching between reading or writing
without an intervening positioning function. Many
implementations are lenient about this, but Solaris libc
will flush the recently-read contents to the output buffer.
In this instance, that meant writing the non-echoed password
that the user just typed to the terminal.

Fix it by inserting a no-op fseek between the read and
write.

The opposite direction (writing followed by reading) is also
disallowed, but our intervening fflush is an acceptable
positioning function for that alternative.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Aug 7, 2012
1 parent 21aeafc commit 67ba123
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions compat/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ char *git_terminal_prompt(const char *prompt, int echo)

r = strbuf_getline(&buf, fh, '\n');
if (!echo) {
fseek(fh, SEEK_CUR, 0);
putc('\n', fh);
fflush(fh);
}
Expand Down

0 comments on commit 67ba123

Please sign in to comment.