]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Guard against uninitialized default locale.
authorJeff Davis <jdavis@postgresql.org>
Mon, 8 Jun 2026 20:11:59 +0000 (13:11 -0700)
committerJeff Davis <jdavis@postgresql.org>
Mon, 8 Jun 2026 20:11:59 +0000 (13:11 -0700)
No known problem today, but defend against issues like dbf217c1c7 in
the future.

Discussion: https://postgr.es/m/d080287d8d2d14c246c86be2e9eb611fb6b27b11.camel@j-davis.com
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Backpatch-through: 17

src/backend/utils/adt/pg_locale.c

index 276d78d07c000101fdaa9eb1d7970f484165a1d1..31c35c48e38ab9d29739f0070a31cd0b6f32f16b 100644 (file)
@@ -1361,6 +1361,10 @@ lc_collate_is_c(Oid collation)
                if (result >= 0)
                        return (bool) result;
 
+               /* should not happen: CheckMyDatabase() not yet run */
+               if (default_locale.provider == '\0')
+                       elog(ERROR, "default locale not initialized");
+
                if (default_locale.provider == COLLPROVIDER_BUILTIN)
                {
                        result = true;
@@ -1428,6 +1432,10 @@ lc_ctype_is_c(Oid collation)
                if (result >= 0)
                        return (bool) result;
 
+               /* should not happen: CheckMyDatabase() not yet run */
+               if (default_locale.provider == '\0')
+                       elog(ERROR, "default locale not initialized");
+
                if (default_locale.provider == COLLPROVIDER_BUILTIN)
                {
                        localeptr = default_locale.info.builtin.locale;
@@ -1586,6 +1594,10 @@ pg_newlocale_from_collation(Oid collid)
 
        if (collid == DEFAULT_COLLATION_OID)
        {
+               /* should not happen: CheckMyDatabase() not yet run */
+               if (default_locale.provider == '\0')
+                       elog(ERROR, "default locale not initialized");
+
                if (default_locale.provider == COLLPROVIDER_LIBC)
                        return (pg_locale_t) 0;
                else