pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Be more wary about OpenSSL not setting errno on error.
6+ messages / 1 participants
[nested] [flat]

* pgsql: Be more wary about OpenSSL not setting errno on error.
@ 2023-12-11 16:52 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2023-12-11 16:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0a5c46a7a488f2f4260a90843bb9de6c584c7f4e

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Be more wary about OpenSSL not setting errno on error.
@ 2023-12-11 16:52 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2023-12-11 16:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ebbd499d4b55c6a6223e01e914308f4a3b936a88

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Be more wary about OpenSSL not setting errno on error.
@ 2023-12-11 16:52 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2023-12-11 16:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/551d4b28e4453fce5890c0df7121bae44b417ec2

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Be more wary about OpenSSL not setting errno on error.
@ 2023-12-11 16:52 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2023-12-11 16:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/07ce2432682d1b2d593d15283fe66e88cb27285e

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Be more wary about OpenSSL not setting errno on error.
@ 2023-12-11 16:52 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2023-12-11 16:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/87b46ad9049162c8588fd858ecd465b820283ea8

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Be more wary about OpenSSL not setting errno on error.
@ 2023-12-11 16:52 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2023-12-11 16:52 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2023-12-11 16:52 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-12-11 16:52 pgsql: Be more wary about OpenSSL not setting errno on error. Tom Lane <tgl@sss.pgh.pa.us>
2023-12-11 16:52 pgsql: Be more wary about OpenSSL not setting errno on error. Tom Lane <tgl@sss.pgh.pa.us>
2023-12-11 16:52 pgsql: Be more wary about OpenSSL not setting errno on error. Tom Lane <tgl@sss.pgh.pa.us>
2023-12-11 16:52 pgsql: Be more wary about OpenSSL not setting errno on error. Tom Lane <tgl@sss.pgh.pa.us>
2023-12-11 16:52 pgsql: Be more wary about OpenSSL not setting errno on error. Tom Lane <tgl@sss.pgh.pa.us>
2023-12-11 16:52 pgsql: Be more wary about OpenSSL not setting errno on error. Tom Lane <tgl@sss.pgh.pa.us>

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