pgsql: Avoid thread-safety problem in ecpglib.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid thread-safety problem in ecpglib.
Date: 2019-01-21 17:07:09
Message-ID: E1gld2T-0005J5-BY@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid thread-safety problem in ecpglib.

ecpglib attempts to force the LC_NUMERIC locale to "C" while reading
server output, to avoid problems with strtod() and related functions.
Historically it's just issued setlocale() calls to do that, but that
has major problems if we're in a threaded application. setlocale()
itself is not required by POSIX to be thread-safe (and indeed is not,
on recent OpenBSD). Moreover, its effects are process-wide, so that
we could cause unexpected results in other threads, or another thread
could change our setting.

On platforms having uselocale(), which is required by POSIX:2008,
we can avoid these problems by using uselocale() instead. Windows
goes its own way as usual, but we can make it safe by using
_configthreadlocale(). Platforms having neither continue to use the
old code, but that should be pretty much nobody among current systems.

This should get back-patched, but let's see what the buildfarm
thinks of it first.

Michael Meskes and Tom Lane; thanks also to Takayuki Tsunakawa.

Discussion: https://postgr.es/m/31420.1547783697@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8eb4a9312c95be56cdb31f5411eddc2cb2ba89be

Modified Files
--------------
configure | 2 +-
configure.in | 1 +
src/include/pg_config.h.in | 3 ++
src/include/pg_config.h.win32 | 3 ++
src/interfaces/ecpg/ecpglib/descriptor.c | 37 +++++++++++++++++++-----
src/interfaces/ecpg/ecpglib/ecpglib_extern.h | 11 ++++++++
src/interfaces/ecpg/ecpglib/execute.c | 42 +++++++++++++++++++++++++++-
7 files changed, 90 insertions(+), 9 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2019-01-21 17:27:49 pgsql: Fix ALTER TRIGGER ... RENAME, broken in WITH OIDS removal.
Previous Message Stephen Frost 2019-01-21 17:00:31 Re: pgsql: Remove references to Majordomo