summaryrefslogtreecommitdiff
path: root/src/bin/psql/input.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-11-26 00:26:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-11-26 00:26:23 +0000
commit739259d62e6f96afecea1470c69004631d7aa264 (patch)
treee1e9f58dda5d66578f0356bf7593fec8acbaa849 /src/bin/psql/input.c
parent8a10096440eaf1f5b918aebec71c2d5ad2687fe6 (diff)
Adjust the behavior of the PQExpBuffer code to make it have well-defined
results (ie, an empty "broken" buffer) if memory overrun occurs anywhere along the way to filling the buffer. The previous coding would just silently discard portions of the intended buffer contents, as exhibited in trouble report from Sam Mason. Also, tweak psql's main loop to correctly detect and report such overruns. There's probably much more that should be done in this line, but this is a start.
Diffstat (limited to 'src/bin/psql/input.c')
-rw-r--r--src/bin/psql/input.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index 6a12dc9ff51..5865a2e4b6e 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.64 2008/01/01 19:45:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.65 2008/11/26 00:26:23 tgl Exp $
*/
#include "postgres_fe.h"
@@ -184,7 +184,8 @@ gets_fromFile(FILE *source)
{
if (ferror(source))
{
- psql_error("could not read from input file: %s\n", strerror(errno));
+ psql_error("could not read from input file: %s\n",
+ strerror(errno));
return NULL;
}
break;
@@ -192,6 +193,12 @@ gets_fromFile(FILE *source)
appendPQExpBufferStr(buffer, line);
+ if (PQExpBufferBroken(buffer))
+ {
+ psql_error("out of memory\n");
+ return NULL;
+ }
+
/* EOL? */
if (buffer->data[buffer->len - 1] == '\n')
{