Skip to content

Commit 681690f

Browse files
committed
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.
1 parent c556447 commit 681690f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/backend/utils/error/elog.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.104.2.1 2005/10/14 16:41:41 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.104.2.2 2007/07/21 22:12:38 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -429,13 +429,18 @@ elog(int lev, const char *fmt,...)
429429
free(msg_buf);
430430

431431
/*
432-
* If the user wants this elog() generating query logged, do so. We
433-
* only want to log if the query has been written to
434-
* debug_query_string. Also, avoid infinite loops.
432+
* If the user wants this elog() generating query logged, do so.
433+
* To avoid possible infinite recursion, temporarily clear
434+
* debug_query_string while recursing.
435435
*/
436+
if (lev >= log_min_error_statement && debug_query_string)
437+
{
438+
char *q_str = debug_query_string;
436439

437-
if (lev != LOG && lev >= log_min_error_statement && debug_query_string)
438-
elog(LOG, "statement: %s", debug_query_string);
440+
debug_query_string = NULL;
441+
elog(LOG, "statement: %s", q_str);
442+
debug_query_string = q_str;
443+
}
439444

440445
/*
441446
* Perform error recovery action as specified by lev.

0 commit comments

Comments
 (0)