Fix segmentation fault when application name is included in log_line_prefix.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 4 Jun 2020 02:29:33 +0000 (11:29 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 4 Jun 2020 02:31:02 +0000 (11:31 +0900)
In Pgpool-II 4.1 or before log_line_prefix unconditionally tried to
fetch the application name from backend info (slots array).
Unfortunately in certain corner cases this was not possible. When
connection_cache is off, pgpool resets connection slots
(session->backend->slots[]) at the time when clients sends termination
request to pgpool. If log_min_messages is DEBUG5, pgpool wants to emit
this log message:

         DEBUG: RESET ALL CONFIG VARIABLE

which caused a segfault because pgpool tried to refer NULL pointer.
Fix is, if session->backend->slots[] is NULL, do not try to fetch
application name from the variable.

Per bug 615.

src/utils/error/elog.c

index 3bcde5123e3ebd5ccace77367e27dfe2d1d2792d..a9e22f2577e1ab5ac335756a4818bf1f7140d73f 100644 (file)
@@ -2003,7 +2003,8 @@ log_line_prefix(StringInfo buf, const char *line_prefix, ErrorData *edata)
                                 * 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 ;
+                               StartupPacket *sp = (session && session->backend && (session->backend->slots[REAL_MASTER_NODE_ID]))? \
+                                               (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]";