Skip to content

Commit e8a72c0

Browse files
committed
Prevent simple_prompt() from locking up in a tight loop at stdin EOF.
1 parent 0a829cb commit e8a72c0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/bin/psql/common.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.25 2000/11/13 23:37:53 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.26 2000/11/27 01:28:40 tgl Exp $
77
*/
88
#include "postgres.h"
99
#include "common.h"
@@ -217,12 +217,14 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
217217
if (length > 0 && destination[length - 1] != '\n')
218218
{
219219
/* eat rest of the line */
220-
char buf[512];
220+
char buf[128];
221+
int buflen;
221222

222223
do
223224
{
224-
fgets(buf, 512, stdin);
225-
} while (buf[strlen(buf) - 1] != '\n');
225+
fgets(buf, sizeof(buf), stdin);
226+
buflen = strlen(buf);
227+
} while (buflen > 0 && buf[buflen - 1] != '\n');
226228
}
227229

228230
if (length > 0 && destination[length - 1] == '\n')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy