mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
Pay attention to failure returns from fgets() in all cases.
Avoid infinite loop prompting for password at stdin EOF.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.26 2000/11/27 01:28:40 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.27 2000/11/27 02:20:36 tgl Exp $
|
||||
*/
|
||||
#include "postgres.h"
|
||||
#include "common.h"
|
||||
@@ -201,7 +201,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
|
||||
}
|
||||
#endif
|
||||
|
||||
fgets(destination, maxlen, stdin);
|
||||
if (fgets(destination, maxlen, stdin) == NULL)
|
||||
destination[0] = '\0';
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
if (!echo)
|
||||
@@ -222,7 +223,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
|
||||
|
||||
do
|
||||
{
|
||||
fgets(buf, sizeof(buf), stdin);
|
||||
if (fgets(buf, sizeof(buf), stdin) == NULL)
|
||||
break;
|
||||
buflen = strlen(buf);
|
||||
} while (buflen > 0 && buf[buflen - 1] != '\n');
|
||||
}
|
||||
@@ -389,9 +391,9 @@ SendQuery(const char *query)
|
||||
"***(press return to proceed or enter x and return to cancel)********************\n",
|
||||
query);
|
||||
fflush(stdout);
|
||||
fgets(buf, 3, stdin);
|
||||
if (buf[0] == 'x')
|
||||
return false;
|
||||
if (fgets(buf, sizeof(buf), stdin) != NULL)
|
||||
if (buf[0] == 'x')
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user