From 943147ea0132e099ab8efb8268431674b9b81745 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 1 Oct 2003 11:11:02 +0000 Subject: [PATCH] Don't echo the password on Solaris, HP-UX, AIX, OSF/1. --- lib/ChangeLog | 5 +++++ lib/getpass.c | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index ebaadd6b6..770685e8b 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2003-10-01 Larry Jones + + * getpass.c (getpass): Use a no-op fseek when switching from input to + output mode on the same stream. + 2003-09-29 Paul Eggert * strftime.c (tm_diff) [! HAVE_TM_GMTOFF]: diff --git a/lib/getpass.c b/lib/getpass.c index 1ab621bcc..d2668ec5e 100644 --- a/lib/getpass.c +++ b/lib/getpass.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992,93,94,95,96,97,98,99,2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1992-2001, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -22,6 +22,7 @@ #include #include #include +#include #include "getline.h" #include "unlocked-io.h" @@ -84,8 +85,18 @@ getpass (const char *prompt) /* Remove the newline. */ buf[nread - 1] = '\0'; if (tty_changed) - /* Write the newline that was not echoed. */ - putc ('\n', out); + { + /* Write the newline that was not echoed. + But before doing that, do a no-op fseek. According to the C + standard, input may not be followed by output on the same + stream without an intervening call to a file positioning + function. Without this fseek() call, on Solaris, HP-UX, + AIX, OSF/1, the previous input gets echoed, whereas on IRIX, + the following newline is not output as it should. */ + if (out == in) + fseek (out, 0, SEEK_CUR); + putc ('\n', out); + } } } -- 2.11.0