From: Tom Lane Date: Sat, 21 Jul 2007 22:12:38 +0000 (+0000) Subject: Fix elog.c to avoid infinite recursion (leading to backend crash) when X-Git-Tag: REL7_3_20~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=681690f4e374d88877ea2f4de1baa04f780abd8e;p=thirdparty%2Fpostgresql.git Fix elog.c to avoid infinite recursion (leading to backend crash) when log_min_error_statement is active and there is some problem in logging the current query string; for example, that it's too long to include in the log message without running out of memory. This problem has existed since the log_min_error_statement feature was introduced. No doubt the reason it wasn't detected long ago is that 8.2 is the first release that defaults log_min_error_statement to less than PANIC level. Per report from Bill Moran. --- diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index b2b431a984e..513288cd08b 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.104.2.1 2005/10/14 16:41:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.104.2.2 2007/07/21 22:12:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -429,13 +429,18 @@ elog(int lev, const char *fmt,...) free(msg_buf); /* - * If the user wants this elog() generating query logged, do so. We - * only want to log if the query has been written to - * debug_query_string. Also, avoid infinite loops. + * If the user wants this elog() generating query logged, do so. + * To avoid possible infinite recursion, temporarily clear + * debug_query_string while recursing. */ + if (lev >= log_min_error_statement && debug_query_string) + { + char *q_str = debug_query_string; - if (lev != LOG && lev >= log_min_error_statement && debug_query_string) - elog(LOG, "statement: %s", debug_query_string); + debug_query_string = NULL; + elog(LOG, "statement: %s", q_str); + debug_query_string = q_str; + } /* * Perform error recovery action as specified by lev.