8000 Don't call pgwin32_message_to_UTF16() without CurrentMemoryContext. · koderP/postgres@d74db7a · GitHub
[go: up one dir, main page]

Skip to content

Commit d74db7a

Browse files
committed
Don't call pgwin32_message_to_UTF16() without CurrentMemoryContext.
PostgreSQL running as a Windows service crashed upon calling write_stderr() before MemoryContextInit(). This fix completes work started in 5735efe. Messages this early contain only ASCII bytes; if we removed the CurrentMemoryContext requirement, the ensuing conversions would have no effect. Back-patch to 9.3 (all supported versions). Takayuki Tsunakawa, reviewed by Michael Paquier. Discussion: https://postgr.es/m/0A3221C70F24FB45833433255569204D1F80CC73@G01JPEXMBYT05
1 parent ef73c35 commit d74db7a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/backend/utils/error/elog.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,10 +2094,15 @@ write_eventlog(int level, const char *line, int len)
20942094
* try to convert the message to UTF16 and write it with ReportEventW().
20952095
* Fall back on ReportEventA() if conversion failed.
20962096
*
2097+
* Since we palloc the structure required for conversion, also fall
2098+
* through to writing unconverted if we have not yet set up
2099+
* CurrentMemoryContext.
2100+
*
20972101
* Also verify that we are not on our way into error recursion trouble due
20982102
* to error messages thrown deep inside pgwin32_message_to_UTF16().
20992103
*/
21002104
if (!in_error_recursion_trouble() &&
2105+
CurrentMemoryContext != NULL &&
21012106
GetMessageEncoding() != GetACPEncoding())
21022107
{
21032108
utf16 = pgwin32_message_to_UTF16(line, len, NULL);

src/backend/utils/mb/mbutils.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,10 @@ GetMessageEncoding(void)
10491049

10501050
#ifdef WIN32
10511051
/*
1052-
* Result is palloc'ed null-terminated utf16 string. The character length
1053-
* is also passed to utf16len if not null. Returns NULL iff failed.
1052+
* Convert from MessageEncoding to a palloc'ed, null-terminated utf16
1053+
* string. The character length is also passed to utf16len if not
1054+
* null. Returns NULL iff failed. Before MessageEncoding initialization, "str"
1055+
* should be ASCII-only; this will function as though MessageEncoding is UTF8.
10541056
*/
10551057
WCHAR *
10561058
pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)

0 commit comments

Comments
 (0)
0