pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid thread-safety problem in ecpglib.
Date: Tue, 22 Jan 2019 04:19:24 +0000
Message-ID: <E1glnX2-00024m-0d@gemulon.postgresql.org> (raw)

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.

(Subsequent buildfarm results show that recent NetBSD versions still
lack uselocale(), but it's not a big problem because they also do not
support non-"C" settings for LC_NUMERIC.)

Back-patch of commits 8eb4a9312 and ee27584c4.

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

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

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6106f9dd71ff5f80fdaa41aa0e39f550967e2040

Modified Files
--------------
configure                                | 13 +++++++++-
configure.in                             | 29 +++++++++++++++++++++-
src/include/pg_config.h.in               |  6 +++++
src/include/pg_config.h.win32            |  6 +++++
src/interfaces/ecpg/ecpglib/descriptor.c | 37 ++++++++++++++++++++++------
src/interfaces/ecpg/ecpglib/execute.c    | 42 +++++++++++++++++++++++++++++++-
src/interfaces/ecpg/ecpglib/extern.h     | 11 +++++++++
7 files changed, 134 insertions(+), 10 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1glnX2-00024m-0d@gemulon.postgresql.org>
Permalink:  ../E1glnX2-00024m-0d@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1glnX2-00024m-0d@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Avoid thread-safety problem in ecpglib.
  In-Reply-To: <E1glnX2-00024m-0d@gemulon.postgresql.org>
  References: <E1glnX2-00024m-0d@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox