From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Fix PGLC_localeconv() to handle errors better. |
Date: | 2016-11-21 23:22:22 |
Message-ID: | E1c8xuo-0005qs-Ua@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Fix PGLC_localeconv() to handle errors better.
The code was intentionally not very careful about leaking strdup'd
strings in case of an error. That was forgivable probably, but it
also failed to notice strdup() failures, which could lead to subsequent
null-pointer-dereference crashes, since many callers unsurprisingly
didn't check for null pointers in the struct lconv fields. An even
worse problem is that it could throw error while we were setlocale'd
to a non-C locale, causing unwanted behavior in subsequent libc calls.
Rewrite to ensure that we cannot throw elog(ERROR) until after we've
restored the previous locale settings, or at least attempted to.
(I'm sorely tempted to make restore failure be a FATAL error, but
will refrain for the moment.) Having done that, it's not much more
work to ensure that we clean up strdup'd storage on the way out, too.
This code is substantially the same in all supported branches, so
back-patch all the way.
Michael Paquier and Tom Lane
Discussion: <CAB7nPqRMbGqa_mesopcn4MPyTs34eqtVEK7ELYxvvV=oqS00YA(at)mail(dot)gmail(dot)com>
Branch
------
REL9_4_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/e702aea4f7d91502bc3db16bb494012e1bc99d11
Modified Files
--------------
src/backend/utils/adt/pg_locale.c | 216 +++++++++++++++++++++++++++++---------
1 file changed, 164 insertions(+), 52 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2016-11-22 00:46:43 | Re: [COMMITTERS] pgsql: autovacuum: Drop orphan temp tables more quickly but with more c |
Previous Message | Tom Lane | 2016-11-21 18:19:34 | pgsql: Fix optimization for skipping searches for parallel-query hazard |