Add a guard against uninitialized default locale
Not known to be reachable after dbf217c1c7, but defend against similar
issues in the future. For instance, an extension might encounter the
problem by calling pg_newlocale_from_collation(DEFAULT_COLLATION_OID)
from _PG_init(), and end up with a NULL pointer dereference.
Backport through 17, though patch is different in 17 (also attached).
Regards,
Jeff Davis
Attachments:
v1.19-0001-Guard-against-uninitialized-default-locale.patchtext/x-patch; charset=UTF-8; name=v1.19-0001-Guard-against-uninitialized-default-locale.patchDownload+6-1
v1.17-0001-Guard-against-uninitialized-default-locale.patchtext/x-patch; charset=UTF-8; name=v1.17-0001-Guard-against-uninitialized-default-locale.patchDownload+12-1
On Fri, 2026-04-24 at 15:44 -0700, Jeff Davis wrote:
Not known to be reachable after dbf217c1c7, but defend against
similar
issues in the future. For instance, an extension might encounter the
problem by calling pg_newlocale_from_collation(DEFAULT_COLLATION_OID)
from _PG_init(), and end up with a NULL pointer dereference.Backport through 17, though patch is different in 17 (also attached).
I plan to commit and backport this soon.
Regards,
Jeff Davis
Hi,
On Fri, 15 May 2026 at 03:30, Jeff Davis <pgsql@j-davis.com> wrote:
On Fri, 2026-04-24 at 15:44 -0700, Jeff Davis wrote:
Not known to be reachable after dbf217c1c7, but defend against
similar
issues in the future. For instance, an extension might encounter the
problem by calling pg_newlocale_from_collation(DEFAULT_COLLATION_OID)
from _PG_init(), and end up with a NULL pointer dereference.Backport through 17, though patch is different in 17 (also attached).
I plan to commit and backport this soon.
The patch looks good to me as it is.
Just one nit in PG 17 patch:
The provider == '\0' sentinel is correct (valid
providers are 'b'/'c'/'i'/'d', all nonzero) and the three guarded
sites (lc_collate_is_c, lc_ctype_is_c, pg_newlocale_from_collation)
cover the direct consumers symmetrically. The only thing maybe
consider is replacing the bare /* should not happen */ above the
'\0' test with something like /* provider unset; init_database_-
collation() not yet run */ -- the literal '\0' check reads as a bit
magical otherwise, but maybe you are doing that to have same
comment throughout.
Regards,
Ayush