Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5521d81

Browse files
committed
Fix race condition in gettext() initialization in libpq and ecpglib.
In libpq and ecpglib, multiple threads can concurrently enter theinitialization logic for message localization. Since we set theits-done flag before actually doing the work, it'd be possiblefor some threads to reach gettext() before anyone has calledbindtextdomain(). Barring bugs in libintl itself, this would notresult in anything worse than failure to localize some earlymessages. Nonetheless, it's a bug, and an easy one to fix.Noted while investigating bug #17299 from Clemens Zeidler(much thanks to Liam Bowen for followup investigation on that).It currently appears that that actually *is* a bug in libintl itself,but that doesn't let us off the hook for this bit.Back-patch to all supported versions.Discussion:https://postgr.es/m/17299-7270741958c0b1ab@postgresql.orgDiscussion:https://postgr.es/m/CAE7q7Eit4Eq2=bxce=Fm8HAStECjaXUE=WBQc-sDDcgJQ7s7eg@mail.gmail.com
1 parent1c6d055 commit5521d81

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

‎src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,14 @@ win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void))
496496
char*
497497
ecpg_gettext(constchar*msgid)
498498
{
499-
staticboolalready_bound= false;
499+
/*
500+
* If multiple threads come through here at about the same time, it's okay
501+
* for more than one of them to call bindtextdomain(). But it's not okay
502+
* for any of them to reach dgettext() before bindtextdomain() is
503+
* complete, so don't set the flag till that's done. Use "volatile" just
504+
* to be sure the compiler doesn't try to get cute.
505+
*/
506+
staticvolatileboolalready_bound= false;
500507

501508
if (!already_bound)
502509
{
@@ -508,12 +515,12 @@ ecpg_gettext(const char *msgid)
508515
#endif
509516
constchar*ldir;
510517

511-
already_bound= true;
512518
/* No relocatable lookup here because the binary could be anywhere */
513519
ldir=getenv("PGLOCALEDIR");
514520
if (!ldir)
515521
ldir=LOCALEDIR;
516522
bindtextdomain(PG_TEXTDOMAIN("ecpglib"),ldir);
523+
already_bound= true;
517524
#ifdefWIN32
518525
SetLastError(save_errno);
519526
#else

‎src/interfaces/libpq/fe-misc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,14 @@ PQenv2encoding(void)
12731273
staticvoid
12741274
libpq_binddomain()
12751275
{
1276-
staticboolalready_bound= false;
1276+
/*
1277+
* If multiple threads come through here at about the same time, it's okay
1278+
* for more than one of them to call bindtextdomain(). But it's not okay
1279+
* for any of them to return to caller before bindtextdomain() is
1280+
* complete, so don't set the flag till that's done. Use "volatile" just
1281+
* to be sure the compiler doesn't try to get cute.
1282+
*/
1283+
staticvolatileboolalready_bound= false;
12771284

12781285
if (!already_bound)
12791286
{
@@ -1285,12 +1292,12 @@ libpq_binddomain()
12851292
#endif
12861293
constchar*ldir;
12871294

1288-
already_bound= true;
12891295
/* No relocatable lookup here because the binary could be anywhere */
12901296
ldir=getenv("PGLOCALEDIR");
12911297
if (!ldir)
12921298
ldir=LOCALEDIR;
12931299
bindtextdomain(PG_TEXTDOMAIN("libpq"),ldir);
1300+
already_bound= true;
12941301
#ifdefWIN32
12951302
SetLastError(save_errno);
12961303
#else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp