[Toybox] [PATCH] Add fflush to lib/password; remove print from stty

Chris Sarra chrissarra at google.com
Wed Sep 16 08:02:27 PDT 2020


Hey Rob,
 I removed that xprintf in stty from our copy a long time ago to get rid of
a log we didn't really need, but that change can be ignored if others find
it useful.
Thanks,
+Chris


On Wed, Sep 16, 2020 at 1:27 AM Rob Landley <rob at landley.net> wrote:

>
>
> On 9/15/20 11:39 AM, Chris Sarra via Toybox wrote:
> > toybox logins were displaying the "password:" prompt after
> > the user entered a password. This patch fixes the issue so the
> > password prompt shows *before* password is entered.
> > ---
> >  lib/password.c      | 1 +
> >  toys/pending/stty.c | 2 +-
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/password.c b/lib/password.c
> > index 432905cc..2f5997ff 100644
> > --- a/lib/password.c
> > +++ b/lib/password.c
> > @@ -63,6 +63,7 @@ int read_password(char *buf, int buflen, char *mesg)
> >    xset_terminal(0, 1, 0, &oldtermio);
> >
> >    xprintf("%s", mesg);
> > +  fflush(NULL);
>
> This is why xprintf() had the x. This is literally why, but actually
> flushing
> before checking for error was too slow. (And then Elliott wanted to enable
> line
> buffering for everything, which breaks tee...)
>
> Sigh, ok I'm replacing it with dprintf() to avoid the borked stdio
> buffering
> entirely, which raises the question should the prompt go to stdout or
> stderr?
>
>   $ sudo /bin/bash
>   [sudo] password for landley:
>   $ sudo /bin/bash 2>/dev/null
>   [sudo] password for landley:
>   $ sudo /bin/bash >/dev/null
>   [sudo] password for landley:
>
> Answer: it goes to /dev/tty. Right, stop, BIG HAMMER time. ("There's never
> time
> to do it right, there's always time to do it over" meets "it is better to
> light
> a flamethrower than to curse the darkness", as usual for this project.)
>
> >    for (i=0; i < buflen-1; i++) {
> >      if ((ret = read(0, buf+i, 1)) < 0 || (!ret && !i)) {
> > diff --git a/toys/pending/stty.c b/toys/pending/stty.c
> > index 8c937696..fe8f5c8d 100644
> > --- a/toys/pending/stty.c
> > +++ b/toys/pending/stty.c
> > @@ -271,7 +271,7 @@ static int set_special_character(struct termios
> *new, int *i, char *char_name)
> >        else if (arg[0] == '^' && arg[2] == 0) ch = (toupper(arg[1])-'@');
> >        else if (!arg[1]) ch = arg[0];
> >        else error_exit("invalid arg: %s", arg);
> > -      xprintf("setting %s to %s (%02x)\n", char_name, arg, ch);
> > +      //xprintf("setting %s to %s (%02x)\n", char_name, arg, ch);
>
> What's this one about? (It's pending, which usually means I'm not as
> familiar
> with the guts of the command...)
>
> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20200916/0dbcc420/attachment.html>


More information about the Toybox mailing list