aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-11-27 01:28:40 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-11-27 01:28:40 +0000
commite8a72c0db22b75144dd2ec0410352dbf34d4bde6 (patch)
tree092f935260a710d5239364be5b2df987468e2592
parent0a829cb8658f8d1c6dfa573689a27f92a28748d9 (diff)
downloadpostgresql-e8a72c0db22b75144dd2ec0410352dbf34d4bde6.tar.gz
postgresql-e8a72c0db22b75144dd2ec0410352dbf34d4bde6.zip
Prevent simple_prompt() from locking up in a tight loop at stdin EOF.
-rw-r--r--src/bin/psql/common.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 658854fc08a..66eeb0ef6b2 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.25 2000/11/13 23:37:53 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.26 2000/11/27 01:28:40 tgl Exp $
*/
#include "postgres.h"
#include "common.h"
@@ -217,12 +217,14 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
if (length > 0 && destination[length - 1] != '\n')
{
/* eat rest of the line */
- char buf[512];
+ char buf[128];
+ int buflen;
do
{
- fgets(buf, 512, stdin);
- } while (buf[strlen(buf) - 1] != '\n');
+ fgets(buf, sizeof(buf), stdin);
+ buflen = strlen(buf);
+ } while (buflen > 0 && buf[buflen - 1] != '\n');
}
if (length > 0 && destination[length - 1] == '\n')