Skip to content

Commit 7829f85

Browse files
committed
Be more careful with error paths in pg_set_regex_collation().
Set global variables after error paths so that they don't end up in an inconsistent state. The inconsistent state doesn't lead to an actual problem, because after an error, pg_set_regex_collation() will be called again before the globals are accessed. Change extracted from patch by Andreas Karlsson, though not discussed explicitly. Discussion: https://postgr.es/m/60929555-4709-40a7-b136-bcb44cff5a3c@proxel.se
1 parent fadff3f commit 7829f85

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/backend/regex/regc_pg_locale.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ static const unsigned char pg_char_properties[128] = {
231231
void
232232
pg_set_regex_collation(Oid collation)
233233
{
234+
pg_locale_t locale = 0;
235+
PG_Locale_Strategy strategy;
236+
234237
if (!OidIsValid(collation))
235238
{
236239
/*
@@ -246,40 +249,41 @@ pg_set_regex_collation(Oid collation)
246249
if (lc_ctype_is_c(collation))
247250
{
248251
/* C/POSIX collations use this path regardless of database encoding */
249-
pg_regex_strategy = PG_REGEX_STRATEGY_C;
250-
pg_regex_locale = 0;
251-
pg_regex_collation = C_COLLATION_OID;
252+
strategy = PG_REGEX_STRATEGY_C;
253+
collation = C_COLLATION_OID;
252254
}
253255
else
254256
{
255-
pg_regex_locale = pg_newlocale_from_collation(collation);
257+
locale = pg_newlocale_from_collation(collation);
256258

257-
if (!pg_locale_deterministic(pg_regex_locale))
259+
if (!pg_locale_deterministic(locale))
258260
ereport(ERROR,
259261
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
260262
errmsg("nondeterministic collations are not supported for regular expressions")));
261263

262-
if (pg_regex_locale->provider == COLLPROVIDER_BUILTIN)
264+
if (locale->provider == COLLPROVIDER_BUILTIN)
263265
{
264266
Assert(GetDatabaseEncoding() == PG_UTF8);
265-
pg_regex_strategy = PG_REGEX_STRATEGY_BUILTIN;
267+
strategy = PG_REGEX_STRATEGY_BUILTIN;
266268
}
267269
#ifdef USE_ICU
268-
else if (pg_regex_locale->provider == COLLPROVIDER_ICU)
270+
else if (locale->provider == COLLPROVIDER_ICU)
269271
{
270-
pg_regex_strategy = PG_REGEX_STRATEGY_ICU;
272+
strategy = PG_REGEX_STRATEGY_ICU;
271273
}
272274
#endif
273275
else
274276
{
275277
if (GetDatabaseEncoding() == PG_UTF8)
276-
pg_regex_strategy = PG_REGEX_STRATEGY_LIBC_WIDE;
278+
strategy = PG_REGEX_STRATEGY_LIBC_WIDE;
277279
else
278-
pg_regex_strategy = PG_REGEX_STRATEGY_LIBC_1BYTE;
280+
strategy = PG_REGEX_STRATEGY_LIBC_1BYTE;
279281
}
280-
281-
pg_regex_collation = collation;
282282
}
283+
284+
pg_regex_strategy = strategy;
285+
pg_regex_locale = locale;
286+
pg_regex_collation = collation;
283287
}
284288

285289
static int

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