Re: [PATCH] Avoid crippled getpass function on Solaris

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 7, 2012 at 8:35 AM, Jeff King <peff@xxxxxxxx> wrote:
> Subject: [PATCH] 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 immediately followed by
> reading) is also disallowed, but our fflush immediately
> after printing the prompt is sufficient to satisfy the
> standard.
> ---
>  compat/terminal.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/compat/terminal.c b/compat/terminal.c
> index 6d16c8f..bbb038d 100644
> --- a/compat/terminal.c
> +++ b/compat/terminal.c
> @@ -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);
>         }

This works. Ben, does this work for you too?

-- 
Cheers,
Ray Chuan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]