postgresql/src/interfaces/libpq
Peter Eisentraut a3c17b2af8 Distrust external OpenSSL clients; clear err queue
OpenSSL has an unfortunate tendency to mix per-session state error
handling with per-thread error handling.  This can cause problems when
programs that link to libpq with OpenSSL enabled have some other use of
OpenSSL; without care, one caller of OpenSSL may cause problems for the
other caller.  Backend code might similarly be affected, for example
when a third party extension independently uses OpenSSL without taking
the appropriate precautions.

To fix, don't trust other users of OpenSSL to clear the per-thread error
queue.  Instead, clear the entire per-thread queue ahead of certain I/O
operations when it appears that there might be trouble (these I/O
operations mostly need to call SSL_get_error() to check for success,
which relies on the queue being empty).  This is slightly aggressive,
but it's pretty clear that the other callers have a very dubious claim
to ownership of the per-thread queue.  Do this is both frontend and
backend code.

Finally, be more careful about clearing our own error queue, so as to
not cause these problems ourself.  It's possibly that control previously
did not always reach SSLerrmessage(), where ERR_get_error() was supposed
to be called to clear the queue's earliest code.  Make sure
ERR_get_error() is always called, so as to spare other users of OpenSSL
the possibility of similar problems caused by libpq (as opposed to
problems caused by a third party OpenSSL library like PHP's OpenSSL
extension).  Again, do this is both frontend and backend code.

See bug #12799 and https://bugs.php.net/bug.php?id=68276

Based on patches by Dave Vitek and Peter Eisentraut.

From: Peter Geoghegan <pg@bowt.ie>
2016-05-06 23:47:42 -04:00
..
po Translation updates 2016-03-28 08:44:53 +02:00
test Fix libpq test expected output file 2015-03-11 17:04:27 -03:00
.gitignore Revert error-throwing wrappers for the printf family of functions. 2015-05-19 18:19:38 -04:00
bcc32.mak Revert error-throwing wrappers for the printf family of functions. 2015-05-19 18:19:38 -04:00
exports.txt Rename PQsslAttributes() to PQsslAttributeNames(), and const-ify fully. 2015-11-07 16:13:49 -05:00
fe-auth.c Avoid possibly-unsafe use of Windows' FormatMessage() function. 2016-03-29 11:54:57 -04:00
fe-auth.h Fix libpq's behavior when /etc/passwd isn't readable. 2015-01-11 12:35:44 -05:00
fe-connect.c Fix unwanted flushing of libpq's input buffer when socket EOF is seen. 2015-11-12 13:03:52 -05:00
fe-exec.c Fix documentation for libpq's PQfn(). 2015-03-08 13:35:28 -04:00
fe-lobj.c Cast to (void *) rather than (int *) when passing int64's to PQfn(). 2015-03-08 13:58:28 -04:00
fe-misc.c Fix unwanted flushing of libpq's input buffer when socket EOF is seen. 2015-11-12 13:03:52 -05:00
fe-print.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
fe-protocol2.c Improve handling of out-of-memory in libpq. 2015-07-07 18:47:25 +03:00
fe-protocol3.c Fix out-of-memory error handling in ParameterDescription message processing. 2015-12-14 18:24:58 +02:00
fe-secure-openssl.c Distrust external OpenSSL clients; clear err queue 2016-05-06 23:47:42 -04:00
fe-secure.c Rename PQsslAttributes() to PQsslAttributeNames(), and const-ify fully. 2015-11-07 16:13:49 -05:00
libpq-events.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
libpq-events.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
libpq-fe.h Rename PQsslAttributes() to PQsslAttributeNames(), and const-ify fully. 2015-11-07 16:13:49 -05:00
libpq-int.h Fix unwanted flushing of libpq's input buffer when socket EOF is seen. 2015-11-12 13:03:52 -05:00
libpq.rc.in Stamp 9.5.2. 2016-03-28 16:07:39 -04:00
Makefile Revert error-throwing wrappers for the printf family of functions. 2015-05-19 18:19:38 -04:00
nls.mk Translation updates 2016-02-08 14:21:00 -05:00
pg_service.conf.sample Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
pqexpbuffer.c Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
pqexpbuffer.h Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
pthread-win32.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
README Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
win32.c Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
win32.h Enable compiling with the mingw-w64 32 bit compiler. 2011-12-10 15:35:41 -05:00
win32.mak Revert error-throwing wrappers for the printf family of functions. 2015-05-19 18:19:38 -04:00

src/interfaces/libpq/README

This directory contains the C version of Libpq, the POSTGRES frontend library.