pgsql: Be more wary about OpenSSL not setting errno on error.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Be more wary about OpenSSL not setting errno on error.
Дата
Msg-id E1rCjW7-009i9h-4g@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Be more wary about OpenSSL not setting errno on error.

OpenSSL will sometimes return SSL_ERROR_SYSCALL without having set
errno; this is apparently a reflection of recv(2)'s habit of not
setting errno when reporting EOF.  Ensure that we treat such cases
the same as read EOF.  Previously, we'd frequently report them like
"could not accept SSL connection: Success" which is confusing, or
worse report them with an unrelated errno left over from some
previous syscall.

To fix, ensure that errno is zeroed immediately before the call,
and report its value only when it's not zero afterwards; otherwise
report EOF.

For consistency, I've applied the same coding pattern in libpq's
pqsecure_raw_read().  Bare recv(2) shouldn't really return -1 without
setting errno, but in case it does we might as well cope.

Per report from Andres Freund.  Back-patch to all supported versions.

Discussion: https://postgr.es/m/20231208181451.deqnflwxqoehhxpe@awork3.anarazel.de

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/271d24f31ddd691327d7e32eea7141b33b9eff58

Modified Files
--------------
src/backend/libpq/be-secure-openssl.c    | 15 +++++++++++----
src/backend/libpq/pqcomm.c               | 22 ++++++++++++++++------
src/interfaces/libpq/fe-secure-openssl.c | 16 ++++++++++++----
src/interfaces/libpq/fe-secure.c         |  7 +++++++
4 files changed, 46 insertions(+), 14 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Daniel Gustafsson
Дата:
Сообщение: pgsql: jit: Create void type in the right context
Следующее
От: Daniel Gustafsson
Дата:
Сообщение: Re: pgsql: llvmjit: Use explicit LLVMContextRef for inlining