pgpool2.git / summary / log / commit / refs
commit d493dd2b7d2065fb554654b137ecd587564f0043
Author: Yugo Nagata <nagata@sraoss.co.jp>
Date: Tue Jul 02 02:12:20 2013 +0000
Fix segmentation fault of child that occurs when startup packet has
no PostgreSQL user information.
When a startup packet has no PostgreSQL user specified, pgpool-II
terminated abnormally. You can reproduce it by
$ psql -p 9999 -U ''
If enable_pool_hba is on, a child process terminates by segmentation
fault. Otherwise if enable_pool_hba is off, the error message is
ERROR: pool_discard_cp: cannot get connection pool for user (null) database (null)
In both cases, psql terminates with no message on frontend.
To resolve it, if PostgreSQL user is not specified in startup packet,
the message as following is output to both log and frontend. This is
the same behavior as PostgreSQL.
FATAL: no PostgreSQL user name specified in startup packet
child.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/child.c b/child.c
index e7c15d0ea..506613aee 100644
--- a/child.c
+++ b/child.c
@@ -989,6 +989,28 @@ static StartupPacket *read_startup_packet(POOL_CONNECTION *cp)
return NULL;
}
+ /* Check a user name was given. */
+ if (sp->major != 1234 &&
+ (sp->user == NULL || sp->user[0] == '\0'))
+ {
+ pool_send_fatal_message(cp, sp->major, "28000",
+ "no PostgreSQL user name specified in startup packet",
+ "",
+ "",
+ __FILE__, __LINE__);
+ pool_error("read_startup_packet: no PostgreSQL user name specified in startup packet");
+ pool_free_startup_packet(sp);
+ alarm(0);
+ pool_signal(SIGALRM, SIG_IGN);
+ return NULL;
+ }
+
+ /* The database defaults to ther user name. */
+ if (sp->database == NULL || sp->database[0] == '\0')
+ {
+ sp->database = strdup(sp->user);
+ }
+
pool_debug("Protocol Major: %d Minor: %d database: %s user: %s",
sp->major, sp->minor, sp->database, sp->user);
alarm(0);
@@ -997,8 +1019,8 @@ static StartupPacket *read_startup_packet(POOL_CONNECTION *cp)
}
/*
-* send startup packet
-*/
+ * send startup packet
+ */
int send_startup_packet(POOL_CONNECTION_POOL_SLOT *cp)
{
int len;
@@ -1011,7 +1033,7 @@ int send_startup_packet(POOL_CONNECTION_POOL_SLOT *cp)
/*
* Reuse existing connection
*/
-static bool connect_using_existing_connection(POOL_CONNECTION *frontend,
+static bool connect_using_existing_connection(POOL_CONNECTION *frontend,
POOL_CONNECTION_POOL *backend,
StartupPacket *sp)
{
[parent: 26ed7692523b]