aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1998-01-23 19:22:24 +0000
committerMarc G. Fournier <scrappy@hub.org>1998-01-23 19:22:24 +0000
commitb34c8ec3ec8385043f7542bc886a13230d95ca14 (patch)
treebb4e5ab23985c00e78ef1596b9ad61f3c17fc385 /src
parentb8476a09fe83f83050a528bd9ca10d37fdf3a727 (diff)
downloadpostgresql-b34c8ec3ec8385043f7542bc886a13230d95ca14.tar.gz
postgresql-b34c8ec3ec8385043f7542bc886a13230d95ca14.zip
From: James Hughes <jamesh@interpath.com>
This is a patch to fix crashes in psql when executing queries from an external file. The code also adds error checking to verify that memory for "query" was allocated. The conditional for the block of code was changed from "query == NULL" to "query_alloced == false". The conditional, "query == NULL", was never true. This prevented the memory being allocated for "query". A few lines later, an attempt to write to an un-allocated memory area generated a SIGSEGV causing the frontend to crash.
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/psql.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/bin/psql/psql.c b/src/bin/psql/psql.c
index 939ae237797..ab519b4143c 100644
--- a/src/bin/psql/psql.c
+++ b/src/bin/psql/psql.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.128 1998/01/23 19:21:11 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.129 1998/01/23 19:22:24 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2093,10 +2093,15 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
int paren_level;
char *query_start;
- if (query == NULL)
+ if (query_alloced == false)
{
- query = malloc(MAX_QUERY_BUFFER);
- query_alloced = true;
+ if((query = malloc(MAX_QUERY_BUFFER)) == NULL) {
+
+ perror("Memory Allocation Failed");
+
+ } else {
+ query_alloced = true;
+ }
}
interactive = ((source == stdin) && !pset->notty);