Skip to content

Commit 08e3fd9

Browse files
committed
Fail pgwin32_message_to_UTF16() for SQL_ASCII messages.
The function had been interpreting SQL_ASCII messages as UTF8, throwing an error when they were invalid UTF8. The new behavior is consistent with pg_do_encoding_conversion(). This affects LOG_DESTINATION_STDERR and LOG_DESTINATION_EVENTLOG, which will send untranslated bytes to write() and ReportEventA(). On buildfarm member bowerbird, enabling log_connections caused an error whenever the role name was not valid UTF8. Back-patch to 9.4 (all supported versions). Discussion: https://postgr.es/m/20190512015615.GD1124997@rfd.leadboat.com
1 parent 82ed20e commit 08e3fd9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/backend/utils/mb/mbutils.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,16 @@ GetMessageEncoding(void)
10571057
WCHAR *
10581058
pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)
10591059
{
1060+
int msgenc = GetMessageEncoding();
10601061
WCHAR *utf16;
10611062
int dstlen;
10621063
UINT codepage;
10631064

1064-
codepage = pg_enc2name_tbl[GetMessageEncoding()].codepage;
1065+
if (msgenc == PG_SQL_ASCII)
1066+
/* No conversion is possible, and SQL_ASCII is never utf16. */
1067+
return NULL;
1068+
1069+
codepage = pg_enc2name_tbl[msgenc].codepage;
10651070

10661071
/*
10671072
* Use MultiByteToWideChar directly if there is a corresponding codepage,
@@ -1086,7 +1091,7 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)
10861091
{
10871092
utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str,
10881093
len,
1089-
GetMessageEncoding(),
1094+
msgenc,
10901095
PG_UTF8);
10911096
if (utf8 != str)
10921097
len = strlen(utf8);

0 commit comments

Comments
 (0)