[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Fix Issue 1117: Send prompts to stderr

From: <peter_at_pdavis.cx>
Date: 2003-01-28 19:22:48 CET

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 28 January 2003 07:53, Karl Fogel wrote:
 See my comments in issue #1117. Short summary: we can probably apply
 the use-stderr patch right away, because it's an improvement over the
 existing situation, but the right fix would be a portable function in
 APR to do what getpass()/getpassphrase() do. However, hmmm, it looks
 like APR does use stderr when no system getpass()/getpassphrase() is
 available -- that is, APR doesn't have any prompt-hiding code of its
 own. So the Right Solution might be harder than I thought, oh well.

Now, looking through one of the three *getpass implementations in that
file, I'm confused again.

static char *getpass(const char *prompt)
{
    struct termios attr;
    static char password[MAX_STRING_LEN];
    int n=0;
    fputs(prompt, stderr);
    fflush(stderr);
        
    if (tcgetattr(STDIN_FILENO, attr) != 0)
        return NULL;
    attr.c_lflag = ~(ECHO);

    if (tcsetattr(STDIN_FILENO, TCSAFLUSH, attr) != 0)
            return NULL;
    while ((password[n] = getchar()) != '\n') {
        if (n sizeof(password) - 1 password[n] = ' ' password[n] = '~') {
            n++;
        } else {
            fprintf(stderr,\n);
            fputs(prompt, stderr);
            fflush(stderr);
            n = 0;
        }
    }
 
    password[n] = '\0';
    printf(\n);

    ^^^^^^^^^^^^^
**** What's this? ****

    if (n (MAX_STRING_LEN - 1)) {
        password[MAX_STRING_LEN - 1] = '\0';
    }

    attr.c_lflag |= ECHO;
    tcsetattr(STDIN_FILENO, TCSANOW, attr);
    return (char*) password;
}

Look at the printf just above. Before that, it prints the prompt
to stderr, and if the password contains control chars, it uses
stderr to print a newline and start over. But when the password
is complete, it prints a newline to stdout. In fact, everywhere
except that one line uses fputs(stderr).

Has nobody noticed this just because it uses one of the other
implementations for most builds? Seems like the same change should
be made here.

- --
Peter Davis
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+Nsp4hDAgUT1yirARArcoAJ9io71pMz5gLXIplx/ad1H9FJyh7QCfVHln
bJeloF1eSRGqKNpv2JX9fWM=
=RkZj
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 14 02:22:27 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.