Skip to content

Commit e02571b

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 0b7e76e commit e02571b

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
@@ -2117,10 +2117,15 @@ write_eventlog(int level, const char *line, int len)
21172117
* try to convert the message to UTF16 and write it with ReportEventW().
21182118
* Fall back on ReportEventA() if conversion failed.
21192119
*
2120+
* Since we palloc the structure required for conversion, also fall
2121+
* through to writing unconverted if we have not yet set up
2122+
* CurrentMemoryContext.
2123+
*
21202124
* Also verify that we are not on our way into error recursion trouble due
21212125
* to error messages thrown deep inside pgwin32_message_to_UTF16().
21222126
*/
21232127
if (!in_error_recursion_trouble() &&
2128+
CurrentMemoryContext != NULL &&
21242129
GetMessageEncoding() != GetACPEncoding())
21252130
{
21262131
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
@@ -1038,8 +1038,10 @@ GetMessageEncoding(void)
10381038

10391039
#ifdef WIN32
10401040
/*
1041-
* Result is palloc'ed null-terminated utf16 string. The character length
1042-
* is also passed to utf16len if not null. Returns NULL iff failed.
1041+
* Convert from MessageEncoding to a palloc'ed, null-terminated utf16
1042+
* string. The character length is also passed to utf16len if not
1043+
* null. Returns NULL iff failed. Before MessageEncoding initialization, "str"
1044+
* should be ASCII-only; this will function as though MessageEncoding is UTF8.
10431045
*/
10441046
WCHAR *
10451047
pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy