From: Tatsuo Ishii Date: Tue, 23 Jan 2018 23:01:22 +0000 (+0900) Subject: Fix segfault when %a is in log_line_prefix and debug message is on. X-Git-Tag: V4_0_0_ALPHA1~149 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=e6b4a1ec58ee3d0ca19957f19d643e9a867c26b9;p=pgpool2.git Fix segfault when %a is in log_line_prefix and debug message is on. log_line_prefix() gets called to create a log line prefix string. If "%a" is specified in "log_line_prefix" parameter, log_line_prefix() calls MASTER_CONNECTION macro, which calls pool_virtual_master_db_node_id(), which calls ereport(), which calls log_line_prefix() if debug message is on. This leads to an infinite recursion and a segfault. Fix is, calling MASTER_NODE_ID macro instead of MASTER_CONNECTION macro. Per bug 376. --- diff --git a/src/utils/error/elog.c b/src/utils/error/elog.c index cb3b403af..114083612 100644 --- a/src/utils/error/elog.c +++ b/src/utils/error/elog.c @@ -43,7 +43,7 @@ * overflow.) * * - * Portions Copyright (c) 2003-2015, PgPool Global Development Group + * Portions Copyright (c) 2003-2018, PgPool Global Development Group * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * @@ -1997,7 +1997,13 @@ log_line_prefix(StringInfo buf, const char *line_prefix, ErrorData *edata) { case 'a': /* application name */ { - StartupPacket *sp = session? MASTER_CONNECTION(session->backend)->sp : NULL ; + + /* + * Do not use MASTER_CONNECTION macro here since it calls + * pool_virtual_master_db_node_id() which eventually calls + * ereport() if operated in DEBUG mode. + */ + StartupPacket *sp = session? (session->backend->slots[REAL_MASTER_NODE_ID])->sp : NULL ; const char *appname = sp? sp->application_name : "[No Connection]"; if (appname == NULL || *appname == '\0') appname = "[unknown]";