diff options
author | Thomas Munro <tmunro@postgresql.org> | 2020-11-04 14:58:34 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2021-06-22 13:21:25 +1200 |
commit | 6dcb185bfc38c93c550d7229ab8bc41bfe80f800 (patch) | |
tree | 47f766d87e53fb994b29d6690834d74f595a8842 | |
parent | 33af10c598e2bff55be46eb79f7c785440aa13c5 (diff) | |
download | postgresql-6dcb185bfc38c93c550d7229ab8bc41bfe80f800.tar.gz postgresql-6dcb185bfc38c93c550d7229ab8bc41bfe80f800.zip |
Back-patch "Tolerate version lookup failure for old style Windows locale names."
If users provide old style pre-standardized Windows locale names in a
CREATE COLLATION command, the OS is unable to provide version
information. Continue without capturing version information, rather
than exposing an OS error.
This was originally done in commit 9f12a3b9 for 14 only, to support
future features that might encounter old style names from initdb's
default. It wasn't done in 13 because I didn't consider that users
might actually want to use the old format explicitly (something we
should consider blocking in a future release with a better error
message, but that's not a policy we've decided on yet).
Back-patch to 13, based on the field complaint in pgsql-bugs #17058.
Reported-by: Yasushi Yamashita <developer@yamashi-ta.jp>
Discussion: https://postgr.es/m/17058-b49f5793c912c5aa%40postgresql.org
-rw-r--r-- | src/backend/utils/adt/pg_locale.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 11d05c73acc..94acf82118a 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -1743,10 +1743,22 @@ get_collation_actual_version(char collprovider, const char *collcollate) MultiByteToWideChar(CP_ACP, 0, collcollate, -1, wide_collcollate, LOCALE_NAME_MAX_LENGTH); if (!GetNLSVersionEx(COMPARE_STRING, wide_collcollate, &version)) + { + /* + * GetNLSVersionEx() wants a language tag such as "en-US", not a + * locale name like "English_United States.1252". Until those + * values can be prevented from entering the system, or 100% + * reliably converted to the more useful tag format, tolerate the + * resulting error and report that we have no version data. + */ + if (GetLastError() == ERROR_INVALID_PARAMETER) + return NULL; + ereport(ERROR, (errmsg("could not get collation version for locale \"%s\": error code %lu", collcollate, GetLastError()))); + } collversion = psprintf("%d.%d,%d.%d", (version.dwNLSVersion >> 8) & 0xFFFF, version.dwNLSVersion & 0xFF, |