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

Commit d02768d

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 85ccb68 commit d02768d

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/backend/utils/mb/mbutils.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -1046,11 +1046,16 @@ GetMessageEncoding(void)
10461046
WCHAR *
10471047
pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)
10481048
{
1049+
int msgenc = GetMessageEncoding();
10491050
WCHAR *utf16;
10501051
int dstlen;
10511052
UINT codepage;
10521053

1053-
codepage = pg_enc2name_tbl[GetMessageEncoding()].codepage;
1054+
if (msgenc == PG_SQL_ASCII)
1055+
/* No conversion is possible, and SQL_ASCII is never utf16. */
1056+
return NULL;
1057+
1058+
codepage = pg_enc2name_tbl[msgenc].codepage;
10541059

10551060
/*
10561061
* Use MultiByteToWideChar directly if there is a corresponding codepage,
@@ -1075,7 +1080,7 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)
10751080
{
10761081
utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str,
10771082
len,
1078-
GetMessageEncoding(),
1083+
msgenc,
10791084
PG_UTF8);
10801085
if (utf8 != str)
10811086
len = strlen(utf8);

src/bin/pg_dump/t/010_dump_connstr.pl

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
plan tests => 14;
1515
}
1616

17-
# In a SQL_ASCII database, pgwin32_message_to_UTF16() needs to
18-
# interpret everything as UTF8. We're going to use byte sequences
19-
# that aren't valid UTF-8 strings, so that would fail. Use LATIN1,
20-
# which accepts any byte and has a conversion from each byte to UTF-8.
17+
# We're going to use byte sequences that aren't valid UTF-8 strings. Use
18+
# LATIN1, which accepts any byte and has a conversion from each byte to UTF-8.
2119
$ENV{LC_ALL} = 'C';
2220
$ENV{PGCLIENTENCODING} = 'LATIN1';
2321

src/bin/scripts/t/200_connstr.pl

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
# Tests to check connection string handling in utilities
99

10-
# In a SQL_ASCII database, pgwin32_message_to_UTF16() needs to
11-
# interpret everything as UTF8. We're going to use byte sequences
12-
# that aren't valid UTF-8 strings, so that would fail. Use LATIN1,
13-
# which accepts any byte and has a conversion from each byte to UTF-8.
10+
# We're going to use byte sequences that aren't valid UTF-8 strings. Use
11+
# LATIN1, which accepts any byte and has a conversion from each byte to UTF-8.
1412
$ENV{LC_ALL} = 'C';
1513
$ENV{PGCLIENTENCODING} = 'LATIN1';
1614

0 commit comments

Comments
 (0)