From: Jeff Davis <pgsql@j-davis.com>
To: pgsql-bugs@postgresql.org
Subject: 17: lc_collate_is_c() when LC_CTYPE != LC_COLLATE
Date: Wed, 06 Nov 2024 09:35:27 -0800
Message-ID: <d5081a7f4f6d425c28dd69d1e09b2e78f149e726.camel@j-davis.com> (raw)
Due to a very unfortunate copy-and-paste error in 2d819a08a1, for the
libc provider, lc_collate_is_c() is checking the environment's LC_CTYPE
rather than LC_COLLATE :(
This sort of works if LC_COLLATE=C and LC_CTYPE=en_US.utf8 (or another
real locale), because lc_collate_is_c() returns false and it falls
through to strcoll(), which will observe LC_COLLATE.
But if LC_COLLATE=en_US.utf8 and LC_CTYPE=C, then it's wrong results.
By good fortune, I believe that the latter combination is fairly rare,
which may explain why it evaded manual testing until now. But it's
still pretty bad.
Trivial patch attached, which I intend to commit shortly to 17 only.
The bug does not exist in master due to recent refactoring.
Regards,
Jeff Davis
Attachments:v1-0001-Fix-lc_collate_is_c-when-LC_COLLATE-LC_CTYPE.patch (text/x-patch, 915B) download
From 16f46ad85a37da590c8bfb4081dee380578f6896 Mon Sep 17 00:00:00 2001
From: Jeff Davis <jeff@j-davis.com>
Date: Tue, 5 Nov 2024 17:38:22 -0800
Subject: [PATCH v1] Fix lc_collate_is_c() when LC_COLLATE != LC_CTYPE.
---
src/backend/utils/adt/pg_locale.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.cindex cd5ad1e705..4c85a01b28 100644--- a/src/backend/utils/adt/pg_locale.c+++ b/src/backend/utils/adt/pg_locale.c@@ -1370,9 +1370,9 @@ lc_collate_is_c(Oid collation)
}
else if (default_locale.provider == COLLPROVIDER_LIBC)
{
- localeptr = setlocale(LC_CTYPE, NULL);+ localeptr = setlocale(LC_COLLATE, NULL);
if (!localeptr)
- elog(ERROR, "invalid LC_CTYPE setting");+ elog(ERROR, "invalid LC_COLLATE setting");
}
else
elog(ERROR, "unexpected collation provider '%c'",
--
2.34.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: pgsql@j-davis.com
Subject: Re: 17: lc_collate_is_c() when LC_CTYPE != LC_COLLATE
In-Reply-To: <d5081a7f4f6d425c28dd69d1e09b2e78f149e726.camel@j-davis.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox