Fix segfault when %a is in log_line_prefix and debug message is on.
authorTatsuo Ishii <ishii@postgresql.org>
Tue, 23 Jan 2018 23:01:22 +0000 (08:01 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Tue, 23 Jan 2018 23:01:22 +0000 (08:01 +0900)
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.

src/utils/error/elog.c

index cb3b403af43695a7701ff1a056bc2341bf3ee05e..114083612560388e3c8fd65a0b43f768d404562e 100644 (file)
@@ -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]";