Skip to content

Commit 409f530

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 c3d1131 commit 409f530

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
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);

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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 4 deletions
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)
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