Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b34c8ec

Browse files
committed
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.
1 parent b8476a0 commit b34c8ec

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/bin/psql/psql.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.128 1998/01/23 19:21:11 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.129 1998/01/23 19:22:24 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2093,10 +2093,15 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
20932093
int paren_level;
20942094
char *query_start;
20952095

2096-
if (query == NULL)
2096+
if (query_alloced == false)
20972097
{
2098-
query = malloc(MAX_QUERY_BUFFER);
2099-
query_alloced = true;
2098+
if((query = malloc(MAX_QUERY_BUFFER)) == NULL) {
2099+
2100+
perror("Memory Allocation Failed");
2101+
2102+
} else {
2103+
query_alloced = true;
2104+
}
21002105
}
21012106

21022107
interactive = ((source == stdin) && !pset->notty);

0 commit comments

Comments
 (0)