From 739259d62e6f96afecea1470c69004631d7aa264 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 26 Nov 2008 00:26:23 +0000 Subject: 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. --- src/bin/psql/input.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/bin/psql/input.c') 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') { -- cgit v1.2.3