From 511047afd7f90874b81dd8e39b9ffcde5b255bb4 Mon Sep 17 00:00:00 2001 From: ryanewang Date: Thu, 27 Feb 2025 21:12:32 +0800 Subject: [PATCH] [Patch] Remove unnecessary OpenSSL error judgment --- src/backend/libpq/be-secure-openssl.c | 16 ++++++++++++++++ src/interfaces/libpq/fe-secure-openssl.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c index 486a66b0bf..9f480e7790 100644 --- a/src/backend/libpq/be-secure-openssl.c +++ b/src/backend/libpq/be-secure-openssl.c @@ -767,6 +767,14 @@ be_tls_read(Port *port, void *ptr, size_t len, int *waitfor) errno = 0; ERR_clear_error(); n = SSL_read(port->ssl, ptr, len); + + /* + * If n is greater than 0, SSL_get_error() will return SSL_ERROR_NONE, + * so it can be returned directly when n is greater than 0. + */ + if (n > 0) + return n; + err = SSL_get_error(port->ssl, n); ecode = (err != SSL_ERROR_NONE || n < 0) ? ERR_get_error() : 0; switch (err) @@ -826,6 +834,14 @@ be_tls_write(Port *port, void *ptr, size_t len, int *waitfor) errno = 0; ERR_clear_error(); n = SSL_write(port->ssl, ptr, len); + + /* + * If n is greater than 0, SSL_get_error() will return SSL_ERROR_NONE, + * so it can be returned directly when n is greater than 0. + */ + if (n > 0) + return n; + err = SSL_get_error(port->ssl, n); ecode = (err != SSL_ERROR_NONE || n < 0) ? ERR_get_error() : 0; switch (err) diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index b6fffd7b9b..3ed738f499 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -159,6 +159,14 @@ rloop: SOCK_ERRNO_SET(0); ERR_clear_error(); n = SSL_read(conn->ssl, ptr, len); + + /* + * If n is greater than 0, SSL_get_error() will return SSL_ERROR_NONE, + * so it can be returned directly when n is greater than 0. + */ + if (n > 0) + return n; + err = SSL_get_error(conn->ssl, n); /* @@ -270,6 +278,14 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len) SOCK_ERRNO_SET(0); ERR_clear_error(); n = SSL_write(conn->ssl, ptr, len); + + /* + * If n is greater than 0, SSL_get_error() will return SSL_ERROR_NONE, + * so it can be returned directly when n is greater than 0. + */ + if (n > 0) + return n; + err = SSL_get_error(conn->ssl, n); ecode = (err != SSL_ERROR_NONE || n < 0) ? ERR_get_error() : 0; switch (err) -- 2.39.3 (Apple Git-146)