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

Commit64ebb43

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 parentfd48e5f commit64ebb43

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
@@ -491,7 +491,14 @@ win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void))
491491
char*
492492
ecpg_gettext(constchar*msgid)
493493
{
494-
staticboolalready_bound= false;
494+
/*
495+
* If multiple threads come through here at about the same time, it's okay
496+
* for more than one of them to call bindtextdomain(). But it's not okay
497+
* for any of them to reach dgettext() before bindtextdomain() is
498+
* complete, so don't set the flag till that's done. Use "volatile" just
499+
* to be sure the compiler doesn't try to get cute.
500+
*/
501+
staticvolatileboolalready_bound= false;
495502

496503
if (!already_bound)
497504
{
@@ -503,12 +510,12 @@ ecpg_gettext(const char *msgid)
503510
#endif
504511
constchar*ldir;
505512

506-
already_bound= true;
507513
/* No relocatable lookup here because the binary could be anywhere */
508514
ldir=getenv("PGLOCALEDIR");
509515
if (!ldir)
510516
ldir=LOCALEDIR;
511517
bindtextdomain(PG_TEXTDOMAIN("ecpglib"),ldir);
518+
already_bound= true;
512519
#ifdefWIN32
513520
SetLastError(save_errno);
514521
#else

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

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

12761283
if (!already_bound)
12771284
{
@@ -1283,12 +1290,12 @@ libpq_binddomain(void)
12831290
#endif
12841291
constchar*ldir;
12851292

1286-
already_bound= true;
12871293
/* No relocatable lookup here because the binary could be anywhere */
12881294
ldir=getenv("PGLOCALEDIR");
12891295
if (!ldir)
12901296
ldir=LOCALEDIR;
12911297
bindtextdomain(PG_TEXTDOMAIN("libpq"),ldir);
1298+
already_bound= true;
12921299
#ifdefWIN32
12931300
SetLastError(save_errno);
12941301
#else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp