Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dcbec53

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 dc10deb commit dcbec53

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
@@ -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)