Skip to content
/ git Public
forked from git/git

Commit 67ba123

Browse files
peffgitster
authored andcommitted
terminal: seek when switching between reading and writing
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21aeafc commit 67ba123

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

compat/terminal.c

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ char *git_terminal_prompt(const char *prompt, int echo)
5959

6060
r = strbuf_getline(&buf, fh, '\n');
6161
if (!echo) {
62+
fseek(fh, SEEK_CUR, 0);
6263
putc('\n', fh);
6364
fflush(fh);
6465
}

0 commit comments

Comments
 (0)